From 69a6cb7c47915c32c495c08e69754716798bb81d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Wed, 18 Nov 2015 01:46:58 +0100 Subject: [PATCH] Return strings for special motion vote values. See #1669. --- openslides/motions/serializers.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/openslides/motions/serializers.py b/openslides/motions/serializers.py index d713288e6..762e81420 100644 --- a/openslides/motions/serializers.py +++ b/openslides/motions/serializers.py @@ -114,6 +114,21 @@ class MotionPollSerializer(ModelSerializer): 'votescast', '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): try: result = obj.get_votes().get(value='Yes').weight