Commit 291004e3 authored by Samuel GAIST's avatar Samuel GAIST

[common][serializers] Make ContributionCreationSerializer usable with versionable

This allows to use it with ProtocolTemplates and
possibly Database as well.
parent c80a19b5
...@@ -400,15 +400,20 @@ class ContributionCreationSerializer(ContributionModSerializer): ...@@ -400,15 +400,20 @@ class ContributionCreationSerializer(ContributionModSerializer):
data["name"] = name data["name"] = name
version = data.get("version") version = data.get("version")
if self.Meta.model.objects.filter( kwargs = {
author=user, name=name, version=version "name": name,
).exists(): "version": version,
}
if hasattr(self.Meta.model, "author"):
kwargs["author"] = user
if self.Meta.model.objects.filter(**kwargs).exists():
raise serializers.ValidationError( raise serializers.ValidationError(
"{} {} version {} already exists on this account".format( "{} {} version {} already exists".format(
self.Meta.model.__name__.lower(), name, version self.Meta.model.__name__.lower(), name, version
) )
) )
previous_version = data.get("previous_version") previous_version = data.get("previous_version")
fork_of = data.get("fork_of") fork_of = data.get("fork_of")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment