From 4faf580239e9aec2600c6d66efc4ed08faf2f622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Sch=C3=BCtze?= Date: Sat, 14 Jan 2017 12:07:14 +0100 Subject: [PATCH] Validates open posts field of assignment form (Fixes #2623) --- openslides/assignments/serializers.py | 11 +++++++++++ openslides/assignments/static/js/assignments/site.js | 1 + 2 files changed, 12 insertions(+) diff --git a/openslides/assignments/serializers.py b/openslides/assignments/serializers.py index 730dbc25c..a78c9ac1e 100644 --- a/openslides/assignments/serializers.py +++ b/openslides/assignments/serializers.py @@ -22,6 +22,15 @@ from .models import ( ) +def posts_validator(data): + """ + Validator for open posts. It checks that the values for the open posts are greater than 0. + """ + if (data['open_posts'] and data['open_posts'] is not None and data['open_posts'] < 1): + raise ValidationError({'detail': _('Value for {} must be greater than 0').format('open_posts')}) + return data + + class AssignmentRelatedUserSerializer(ModelSerializer): """ Serializer for assignment.models.AssignmentRelatedUser objects. @@ -198,6 +207,7 @@ class AssignmentFullSerializer(ModelSerializer): 'polls', 'agenda_item_id', 'tags',) + validators = (posts_validator,) class AssignmentShortSerializer(AssignmentFullSerializer): @@ -220,3 +230,4 @@ class AssignmentShortSerializer(AssignmentFullSerializer): 'polls', 'agenda_item_id', 'tags',) + validators = (posts_validator,) diff --git a/openslides/assignments/static/js/assignments/site.js b/openslides/assignments/static/js/assignments/site.js index 7b1618ddb..7ac8e528b 100644 --- a/openslides/assignments/static/js/assignments/site.js +++ b/openslides/assignments/static/js/assignments/site.js @@ -180,6 +180,7 @@ angular.module('OpenSlidesApp.assignments.site', [ templateOptions: { label: gettextCatalog.getString('Number of persons to be elected'), type: 'number', + min: 1, required: true } },