From 136eb02caedaf004b17ef990a82567aaa9af7f8c Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Tue, 22 Jul 2014 10:11:38 +0200 Subject: [PATCH] Validating name on userstory status --- taiga/projects/serializers.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/taiga/projects/serializers.py b/taiga/projects/serializers.py index 7a064655..4b414446 100644 --- a/taiga/projects/serializers.py +++ b/taiga/projects/serializers.py @@ -37,6 +37,23 @@ class UserStoryStatusSerializer(serializers.ModelSerializer): class Meta: model = models.UserStoryStatus + def validate_name(self, attrs, source): + """ + Check the status name is not duplicated in the project on creation + """ + qs = None + # If the milestone exists: + if self.object and attrs.get("name", None): + qs = models.UserStoryStatus.objects.filter(project=self.object.project, name=attrs[source]) + + if not self.object and attrs.get("project", None) and attrs.get("name", None): + qs = models.UserStoryStatus.objects.filter(project=attrs["project"], name=attrs[source]) + + if qs and qs.exists(): + raise serializers.ValidationError("Name duplicated for the project") + + return attrs + # Task common serializers