diff --git a/representatives_votes/serializers.py b/representatives_votes/serializers.py index 48c86425a7be53fad19276f907fe809fead7dc84..a7e51e395e33e093b4fc8919fc990d3f43916859 100644 --- a/representatives_votes/serializers.py +++ b/representatives_votes/serializers.py @@ -14,15 +14,19 @@ class VoteSerializer(serializers.HyperlinkedModelSerializer): fields = ( 'proposal', 'representative', - 'representative_name', 'position' ) + extra_kwargs = { + 'proposal': {'view_name': 'api-proposal-detail'}, + 'representative': {'view_name': 'api-representative-detail'} + } class ProposalSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = models.Proposal fields = ( + 'id', 'dossier', 'title', 'description', @@ -35,14 +39,18 @@ class ProposalSerializer(serializers.HyperlinkedModelSerializer): 'url', ) + extra_kwargs = { + 'dossier': {'view_name': 'api-dossier-detail'}, + 'url': {'view_name': 'api-proposal-detail'} + } + class ProposalDetailSerializer(ProposalSerializer): """ Proposal serializer that includes votes """ votes = VoteSerializer(many=True) - class Meta: - model = models.Proposal + class Meta(ProposalSerializer.Meta): fields = ProposalSerializer.Meta.fields + ('votes',) @@ -52,12 +60,18 @@ class DocumentSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = models.Document fields = ( + 'id', 'dossier', 'chamber', 'kind', 'link' ) + extra_kwargs = { + 'dossier': {'view_name': 'api-dossier-detail'}, + 'chamber': {'view_name': 'api-chamber-detail'} + } + class DossierSerializer(serializers.HyperlinkedModelSerializer): """ Base dossier serializer """ @@ -65,11 +79,15 @@ class DossierSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = models.Dossier fields = ( + 'id', + 'url', 'title', 'reference', 'text', - 'url', ) + extra_kwargs = { + 'url': {'view_name': 'api-dossier-detail'} + } class DossierDetailSerializer(DossierSerializer): @@ -80,6 +98,5 @@ class DossierDetailSerializer(DossierSerializer): proposals = ProposalSerializer(many=True) documents = DocumentSerializer(many=True) - class Meta: - model = models.Dossier - field = DossierSerializer.Meta.fields + ('proposals', 'documents') + class Meta(DossierSerializer.Meta): + fields = DossierSerializer.Meta.fields + ('proposals', 'documents') diff --git a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_dossier.content b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_dossier.content index cd4f3e31226b9b1ed631ec97ed03787bcb939439..8091dd8865728aea556f2a6073bf23d2a741654b 100644 --- a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_dossier.content +++ b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_dossier.content @@ -1,7 +1,12 @@ { + "id": 1, "url": "http://testserver/api/dossiers/1/", + "title": "Agenda for change: the future of EU development policy", + "reference": "2012/2002(INI)", + "text": "", "proposals": [ { + "id": 1, "dossier": "http://testserver/api/dossiers/1/", "title": "A7-0234/2012 - Charles Goerens - § 31", "description": "", @@ -14,6 +19,7 @@ "url": "http://testserver/api/proposals/1/" }, { + "id": 2, "dossier": "http://testserver/api/dossiers/1/", "title": "A7-0234/2012 - Charles Goerens - Résolution", "description": "", @@ -28,15 +34,11 @@ ], "documents": [ { + "id": 1, "dossier": "http://testserver/api/dossiers/1/", "chamber": "http://testserver/api/chambers/1/", "kind": "procedure-file", "link": "http://www.europarl.europa.eu/oeil/popups/ficheprocedure.do?reference=2012/2002(INI)" } - ], - "created": "2015-12-27T11:51:14.770000Z", - "updated": "2015-12-27T11:51:14.770000Z", - "title": "Agenda for change: the future of EU development policy", - "reference": "2012/2002(INI)", - "text": "" + ] } \ No newline at end of file diff --git a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_dossiers.content b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_dossiers.content index 4c5985a1ea64451953337905f6ba3e5a576ca1de..04d0879cc35102c3ad9d2b7308081d11c3ce87da 100644 --- a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_dossiers.content +++ b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_dossiers.content @@ -1,14 +1,16 @@ [ { + "id": 1, + "url": "http://testserver/api/dossiers/1/", "title": "Agenda for change: the future of EU development policy", "reference": "2012/2002(INI)", - "text": "", - "url": "http://testserver/api/dossiers/1/" + "text": "" }, { + "id": 2, + "url": "http://testserver/api/dossiers/2/", "title": "2016 general budget: all sections", "reference": "2015/2132(BUD)", - "text": "", - "url": "http://testserver/api/dossiers/2/" + "text": "" } ] \ No newline at end of file diff --git a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_proposal.content b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_proposal.content index 06a94a59db0d3910f394ee3cda9f57760de8ab2d..24e7a50fff96ddb9f6dc335afb9ad0f0bb6ec8ca 100644 --- a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_proposal.content +++ b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_proposal.content @@ -1,4 +1,5 @@ { + "id": 1, "dossier": "http://testserver/api/dossiers/1/", "title": "A7-0234/2012 - Charles Goerens - § 31", "description": "", @@ -13,13 +14,11 @@ { "proposal": "http://testserver/api/proposals/1/", "representative": "http://testserver/api/representatives/2/", - "representative_name": "", "position": "abstain" }, { "proposal": "http://testserver/api/proposals/1/", "representative": "http://testserver/api/representatives/1/", - "representative_name": "", "position": "abstain" } ] diff --git a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_proposals.content b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_proposals.content index 99d88118451b61db53f9b5d2bf663f670f003a09..f429783cadc76a4df17d841c6d80ddb9510e3686 100644 --- a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_proposals.content +++ b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_proposals.content @@ -1,5 +1,6 @@ [ { + "id": 1, "dossier": "http://testserver/api/dossiers/1/", "title": "A7-0234/2012 - Charles Goerens - § 31", "description": "", @@ -12,6 +13,7 @@ "url": "http://testserver/api/proposals/1/" }, { + "id": 2, "dossier": "http://testserver/api/dossiers/1/", "title": "A7-0234/2012 - Charles Goerens - Résolution", "description": "", @@ -24,6 +26,7 @@ "url": "http://testserver/api/proposals/2/" }, { + "id": 3, "dossier": "http://testserver/api/dossiers/2/", "title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 4", "description": "", @@ -36,6 +39,7 @@ "url": "http://testserver/api/proposals/3/" }, { + "id": 4, "dossier": "http://testserver/api/dossiers/2/", "title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 29", "description": "", @@ -48,6 +52,7 @@ "url": "http://testserver/api/proposals/4/" }, { + "id": 5, "dossier": "http://testserver/api/dossiers/2/", "title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 31", "description": "", @@ -60,6 +65,7 @@ "url": "http://testserver/api/proposals/5/" }, { + "id": 6, "dossier": "http://testserver/api/dossiers/2/", "title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 30", "description": "", diff --git a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_vote.content b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_vote.content index e5a93d5a513186aff387fd9986bd07a31c6ded47..d18a96c5abe1fcc166c2fdf2de078a3eb64e129e 100644 --- a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_vote.content +++ b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_vote.content @@ -1,6 +1,5 @@ { "proposal": "http://testserver/api/proposals/1/", "representative": "http://testserver/api/representatives/2/", - "representative_name": "", "position": "abstain" } \ No newline at end of file diff --git a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_votes.content b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_votes.content index 1ba9d7ef58e2d29b0aafc3064f9577cb9d9bfeec..512659bdd7ea2e9d1e214c8eda4d76ac8af9a53a 100644 --- a/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_votes.content +++ b/representatives_votes/tests/response_fixtures/RepresentativeManagerTest.test_votes.content @@ -2,67 +2,56 @@ { "proposal": "http://testserver/api/proposals/1/", "representative": "http://testserver/api/representatives/2/", - "representative_name": "", "position": "abstain" }, { "proposal": "http://testserver/api/proposals/1/", "representative": "http://testserver/api/representatives/1/", - "representative_name": "", "position": "abstain" }, { "proposal": "http://testserver/api/proposals/2/", "representative": "http://testserver/api/representatives/2/", - "representative_name": "", "position": "for" }, { "proposal": "http://testserver/api/proposals/2/", "representative": "http://testserver/api/representatives/1/", - "representative_name": "", "position": "for" }, { "proposal": "http://testserver/api/proposals/3/", "representative": "http://testserver/api/representatives/2/", - "representative_name": "", "position": "against" }, { "proposal": "http://testserver/api/proposals/3/", "representative": "http://testserver/api/representatives/1/", - "representative_name": "", "position": "against" }, { "proposal": "http://testserver/api/proposals/4/", "representative": "http://testserver/api/representatives/1/", - "representative_name": "", "position": "for" }, { "proposal": "http://testserver/api/proposals/4/", "representative": "http://testserver/api/representatives/2/", - "representative_name": "", "position": "against" }, { "proposal": "http://testserver/api/proposals/5/", "representative": "http://testserver/api/representatives/1/", - "representative_name": "", "position": "abstain" }, { "proposal": "http://testserver/api/proposals/5/", "representative": "http://testserver/api/representatives/2/", - "representative_name": "", "position": "against" }, { "proposal": "http://testserver/api/proposals/6/", "representative": "http://testserver/api/representatives/1/", - "representative_name": "", "position": "for" } ] \ No newline at end of file diff --git a/representatives_votes/tests/urls.py b/representatives_votes/tests/urls.py index 5e058de686c1356d7f9ef21a4cbc1b4fb2db48a6..a43ede32e24a05c4dac753624b37498cf7804c3b 100644 --- a/representatives_votes/tests/urls.py +++ b/representatives_votes/tests/urls.py @@ -11,21 +11,23 @@ from representatives_votes.api import ( from representatives.api import ( ChamberViewSet, ConstituencyViewSet, + CountryViewSet, GroupViewSet, MandateViewSet, RepresentativeViewSet, ) router = routers.DefaultRouter() -router.register(r'chambers', ChamberViewSet) -router.register(r'constituencies', ConstituencyViewSet) -router.register(r'groups', GroupViewSet) -router.register(r'mandates', MandateViewSet) -router.register(r'representatives', RepresentativeViewSet) -router.register(r'dossiers', DossierViewSet) -router.register(r'proposals', ProposalViewSet) -router.register(r'votes', VoteViewSet) +router.register('countries', CountryViewSet, 'api-country') +router.register('chambers', ChamberViewSet, 'api-chamber') +router.register('constituencies', ConstituencyViewSet, 'api-constituency') +router.register('groups', GroupViewSet, 'api-group') +router.register('mandates', MandateViewSet, 'api-mandate') +router.register('representatives', RepresentativeViewSet, 'api-representative') +router.register('dossiers', DossierViewSet, 'api-dossier') +router.register('proposals', ProposalViewSet, 'api-proposal') +router.register('votes', VoteViewSet, 'api-vote') urlpatterns = [ - url(r'api/', include(router.urls)), + url('api/', include(router.urls)), ] diff --git a/setup.py b/setup.py index dacf8e63b875a02186969b1b840e2c979e5cbef5..3c9e9341226d22eadf5a129ca17f552524830a23 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( keywords='django government parliament votes', install_requires=[ 'django>1.8,<1.9', - 'django-representatives>=0.0.32', + 'django-representatives>=0.0.33', 'py-dateutil>=2,<3', 'ijson>=2,<3', 'pytz', # Always use up-to-date TZ data