Merge pull request #1685 from normanjaeckel/VoteString

Return strings for special motion vote values. See #1669.
This commit is contained in:
Oskar Hahn 2015-11-18 12:19:10 +01:00
commit 6dee5d87f0

View File

@ -114,6 +114,21 @@ class MotionPollSerializer(ModelSerializer):
'votescast', 'votescast',
'votes',) 'votes',)
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
translated string 'undocumented'.
"""
result = super().to_representation(obj)
for key in result:
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:
result[key] = _('undocumented')
return result
def get_yes(self, obj): def get_yes(self, obj):
try: try:
result = obj.get_votes().get(value='Yes').weight result = obj.get_votes().get(value='Yes').weight