Enabled possibility to send null for motion poll votes vote value fields.

This commit is contained in:
Norman Jäckel 2015-11-19 19:56:01 +01:00
parent 0cce7f967b
commit 19df7c82a2

View File

@ -98,7 +98,7 @@ class MotionPollSerializer(ModelSerializer):
no = SerializerMethodField() no = SerializerMethodField()
abstain = SerializerMethodField() abstain = SerializerMethodField()
votes = DictField( votes = DictField(
child=IntegerField(min_value=-2), child=IntegerField(min_value=-2, allow_null=True),
write_only=True) write_only=True)
class Meta: class Meta:
@ -117,7 +117,7 @@ class MotionPollSerializer(ModelSerializer):
def to_representation(self, obj): def to_representation(self, obj):
""" """
Overrides the output of this serializer. Replaces vote values -1 Overrides the output of this serializer. Replaces vote values -1
through the translated string 'majority' and -2 or None through the through the translated string 'majority' and -2 through the
translated string 'undocumented'. translated string 'undocumented'.
""" """
result = super().to_representation(obj) result = super().to_representation(obj)
@ -125,7 +125,7 @@ class MotionPollSerializer(ModelSerializer):
if key in ('yes', 'no', 'abstain', 'votesvalid', 'votesinvalid', 'votescast'): if key in ('yes', 'no', 'abstain', 'votesvalid', 'votesinvalid', 'votescast'):
if result[key] == -1: if result[key] == -1:
result[key] = _('majority') result[key] = _('majority')
elif result[key] == -2 or result[key] is None: elif result[key] == -2:
result[key] = _('undocumented') result[key] = _('undocumented')
return result return result