Commit a820284f authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt

use vote_type attribute to determine vote data serialization in poll

parent 428c07ef
......@@ -33,11 +33,11 @@ class PollSerializer(serializers.ModelSerializer):
options = OptionSerializer(many=True, read_only=True)
def to_representation(self, instance):
vote_data = models.resolve_vote(instance)
representation = super().to_representation(instance)
vote_data = models.resolve_vote(instance)
voter_serializer = VoterSerializer()
if 'ranking' in vote_data:
if instance.vote_type is models.VoteType.CONDORCET:
representation.update({
'options_winner': getattr(vote_data['winner'], 'id', None),
'options_ranking': [option.id for option in vote_data['ranking']],
......@@ -51,7 +51,7 @@ class PollSerializer(serializers.ModelSerializer):
) for voter, options in vote_data['votes'].items()
]
})
else:
elif instance.vote_type is models.VoteType.SIMPLE:
representation.update({
'options_winner': getattr(vote_data['winner'], 'id', None),
'options_ranking': [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment