Merge pull request #1688 from normanjaeckel/VotesField

Enabled possibility to send null for motion poll votes vote value fie…
This commit is contained in:
Oskar Hahn 2015-11-19 20:37:11 +01:00
commit 07bd763a63

View File

@ -98,7 +98,7 @@ class MotionPollSerializer(ModelSerializer):
no = SerializerMethodField()
abstain = SerializerMethodField()
votes = DictField(
child=IntegerField(min_value=-2),
child=IntegerField(min_value=-2, allow_null=True),
write_only=True)
class Meta:
@ -117,7 +117,7 @@ class MotionPollSerializer(ModelSerializer):
def to_representation(self, obj):
"""
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'.
"""
result = super().to_representation(obj)
@ -125,7 +125,7 @@ class MotionPollSerializer(ModelSerializer):
if key in ('yes', 'no', 'abstain', 'votesvalid', 'votesinvalid', 'votescast'):
if result[key] == -1:
result[key] = _('majority')
elif result[key] == -2 or result[key] is None:
elif result[key] == -2:
result[key] = _('undocumented')
return result