Skip to content

Commit ec543b6

Browse files
committed
Fixed the API
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.
1 parent 4f7a0e2 commit ec543b6

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

representatives_votes/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DossierViewSet(viewsets.ReadOnlyModelViewSet):
2626
"""
2727

2828
pagination_class = DefaultWebPagination
29-
queryset = Dossier.objects.prefetch_related('proposals__votes__representative')
29+
queryset = Dossier.objects.all()
3030
serializer_class = DossierSerializer
3131

3232
filter_backends = (

representatives_votes/serializers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class ProposalSerializer(serializers.HyperlinkedModelSerializer):
2323
class Meta:
2424
model = models.Proposal
2525
fields = (
26-
'id',
2726
'dossier',
2827
'title',
2928
'description',
@@ -40,29 +39,31 @@ class Meta:
4039
class ProposalDetailSerializer(ProposalSerializer):
4140
""" Proposal serializer that includes votes """
4241

42+
votes = VoteSerializer(many=True)
43+
44+
class Meta:
45+
model = models.Proposal
46+
4347

4448
class DossierSerializer(serializers.HyperlinkedModelSerializer):
4549
""" Base dossier serializer """
46-
proposals = ProposalSerializer(many=True)
4750

4851
class Meta:
4952
model = models.Dossier
5053
fields = (
51-
'id',
5254
'title',
5355
'reference',
5456
'text',
5557
'link',
5658
'url',
57-
'proposals',
5859
)
5960

6061

6162
class DossierDetailSerializer(DossierSerializer):
6263
"""
6364
Dossier serializer that includes proposals and votes.
6465
"""
65-
proposals = ProposalSerializer(many=True)
66+
proposals = ProposalDetailSerializer(many=True)
6667

6768
class Meta:
6869
model = models.Dossier

representatives_votes/tests/test_views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ def test_proposals(self):
3131
def test_vote(self):
3232
self.functional_test(1, '/api/votes/1/')
3333

34+
def test_proposals(self):
35+
self.functional_test(1, '/api/proposals/')
36+
3437
def test_votes(self):
3538
self.functional_test(1, '/api/votes/')

0 commit comments

Comments
 (0)