Skip to content

Commit

Permalink
Fix #58
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusdemorais committed Apr 27, 2018
1 parent 29666fd commit 84de02a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,20 +568,38 @@ def get_queryset(self):
return queryset

def list(self, request):
return super(UserVoteViewset, self).list(request)
response = super(UserVoteViewset, self).list(request)

for vote in response.data['results']:
proposition = Proposition.objects.get(pk=vote['proposition'])
proposition_serializer = PropositionSerializer(proposition)
vote['proposition'] = proposition_serializer.data

return response

def create(self, request):
user_id = request.user.id
request.data['user'] = user_id

return super(UserVoteViewset, self).create(request)
response = super(UserVoteViewset, self).create(request)

proposition = Proposition.objects.get(pk=response.data['proposition'])
proposition_serializer = PropositionSerializer(proposition)
response.data['proposition'] = proposition_serializer.data

return response

def destroy(self, request, pk=None):
response = super(UserVoteViewset, self).destroy(request, pk)
return response

def retrieve(self, request, pk=None):
response = super(UserVoteViewset, self).retrieve(request, pk)

proposition = Proposition.objects.get(pk=response.data['proposition'])
proposition_serializer = PropositionSerializer(proposition)
response.data['proposition'] = proposition_serializer.data

return response

def partial_update(self, request, pk=None, **kwargs):
Expand All @@ -602,6 +620,11 @@ def update(self, request, pk=None, **kwargs):
request,
pk,
**kwargs)

proposition = Proposition.objects.get(pk=response.data['proposition'])
proposition_serializer = PropositionSerializer(proposition)
response.data['proposition'] = proposition_serializer.data

return response


Expand Down

0 comments on commit 84de02a

Please sign in to comment.