Skip to content

Commit

Permalink
Fixed the API
Browse files Browse the repository at this point in the history
It wasn't clear which URL would be what resource, ie. the proposal list
view displayed votes and not the proposal detail view.

Also changed the tests so that they requested indented responses which
will be easier to diff.
  • Loading branch information
jpic committed May 25, 2016
1 parent 4f7a0e2 commit ec543b6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion representatives_votes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DossierViewSet(viewsets.ReadOnlyModelViewSet):
"""

pagination_class = DefaultWebPagination
queryset = Dossier.objects.prefetch_related('proposals__votes__representative')
queryset = Dossier.objects.all()
serializer_class = DossierSerializer

filter_backends = (
Expand Down
11 changes: 6 additions & 5 deletions representatives_votes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class ProposalSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.Proposal
fields = (
'id',
'dossier',
'title',
'description',
Expand All @@ -40,29 +39,31 @@ class Meta:
class ProposalDetailSerializer(ProposalSerializer):
""" Proposal serializer that includes votes """

votes = VoteSerializer(many=True)

class Meta:
model = models.Proposal


class DossierSerializer(serializers.HyperlinkedModelSerializer):
""" Base dossier serializer """
proposals = ProposalSerializer(many=True)

class Meta:
model = models.Dossier
fields = (
'id',
'title',
'reference',
'text',
'link',
'url',
'proposals',
)


class DossierDetailSerializer(DossierSerializer):
"""
Dossier serializer that includes proposals and votes.
"""
proposals = ProposalSerializer(many=True)
proposals = ProposalDetailSerializer(many=True)

class Meta:
model = models.Dossier
Expand Down
3 changes: 3 additions & 0 deletions representatives_votes/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ def test_proposals(self):
def test_vote(self):
self.functional_test(1, '/api/votes/1/')

def test_proposals(self):
self.functional_test(1, '/api/proposals/')

def test_votes(self):
self.functional_test(1, '/api/votes/')

0 comments on commit ec543b6

Please sign in to comment.