Validates open posts field of assignment form (Fixes #2623)

This commit is contained in:
Emanuel Schütze 2017-01-14 12:07:14 +01:00
parent 8c4b38f018
commit 4faf580239
2 changed files with 12 additions and 0 deletions

View File

@ -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,)

View File

@ -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
}
},