Commit 64804481 authored by Nicolas Joyard's avatar Nicolas Joyard

Fix API inconsistencies

parent 45616b4e
...@@ -14,15 +14,19 @@ class VoteSerializer(serializers.HyperlinkedModelSerializer): ...@@ -14,15 +14,19 @@ class VoteSerializer(serializers.HyperlinkedModelSerializer):
fields = ( fields = (
'proposal', 'proposal',
'representative', 'representative',
'representative_name',
'position' 'position'
) )
extra_kwargs = {
'proposal': {'view_name': 'api-proposal-detail'},
'representative': {'view_name': 'api-representative-detail'}
}
class ProposalSerializer(serializers.HyperlinkedModelSerializer): class ProposalSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = models.Proposal model = models.Proposal
fields = ( fields = (
'id',
'dossier', 'dossier',
'title', 'title',
'description', 'description',
...@@ -35,14 +39,18 @@ class ProposalSerializer(serializers.HyperlinkedModelSerializer): ...@@ -35,14 +39,18 @@ class ProposalSerializer(serializers.HyperlinkedModelSerializer):
'url', 'url',
) )
extra_kwargs = {
'dossier': {'view_name': 'api-dossier-detail'},
'url': {'view_name': 'api-proposal-detail'}
}
class ProposalDetailSerializer(ProposalSerializer): class ProposalDetailSerializer(ProposalSerializer):
""" Proposal serializer that includes votes """ """ Proposal serializer that includes votes """
votes = VoteSerializer(many=True) votes = VoteSerializer(many=True)
class Meta: class Meta(ProposalSerializer.Meta):
model = models.Proposal
fields = ProposalSerializer.Meta.fields + ('votes',) fields = ProposalSerializer.Meta.fields + ('votes',)
...@@ -52,12 +60,18 @@ class DocumentSerializer(serializers.HyperlinkedModelSerializer): ...@@ -52,12 +60,18 @@ class DocumentSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = models.Document model = models.Document
fields = ( fields = (
'id',
'dossier', 'dossier',
'chamber', 'chamber',
'kind', 'kind',
'link' 'link'
) )
extra_kwargs = {
'dossier': {'view_name': 'api-dossier-detail'},
'chamber': {'view_name': 'api-chamber-detail'}
}
class DossierSerializer(serializers.HyperlinkedModelSerializer): class DossierSerializer(serializers.HyperlinkedModelSerializer):
""" Base dossier serializer """ """ Base dossier serializer """
...@@ -65,11 +79,15 @@ class DossierSerializer(serializers.HyperlinkedModelSerializer): ...@@ -65,11 +79,15 @@ class DossierSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = models.Dossier model = models.Dossier
fields = ( fields = (
'id',
'url',
'title', 'title',
'reference', 'reference',
'text', 'text',
'url',
) )
extra_kwargs = {
'url': {'view_name': 'api-dossier-detail'}
}
class DossierDetailSerializer(DossierSerializer): class DossierDetailSerializer(DossierSerializer):
...@@ -80,6 +98,5 @@ class DossierDetailSerializer(DossierSerializer): ...@@ -80,6 +98,5 @@ class DossierDetailSerializer(DossierSerializer):
proposals = ProposalSerializer(many=True) proposals = ProposalSerializer(many=True)
documents = DocumentSerializer(many=True) documents = DocumentSerializer(many=True)
class Meta: class Meta(DossierSerializer.Meta):
model = models.Dossier fields = DossierSerializer.Meta.fields + ('proposals', 'documents')
field = DossierSerializer.Meta.fields + ('proposals', 'documents')
{ {
"id": 1,
"url": "http://testserver/api/dossiers/1/", "url": "http://testserver/api/dossiers/1/",
"title": "Agenda for change: the future of EU development policy",
"reference": "2012/2002(INI)",
"text": "",
"proposals": [ "proposals": [
{ {
"id": 1,
"dossier": "http://testserver/api/dossiers/1/", "dossier": "http://testserver/api/dossiers/1/",
"title": "A7-0234/2012 - Charles Goerens - § 31", "title": "A7-0234/2012 - Charles Goerens - § 31",
"description": "", "description": "",
...@@ -14,6 +19,7 @@ ...@@ -14,6 +19,7 @@
"url": "http://testserver/api/proposals/1/" "url": "http://testserver/api/proposals/1/"
}, },
{ {
"id": 2,
"dossier": "http://testserver/api/dossiers/1/", "dossier": "http://testserver/api/dossiers/1/",
"title": "A7-0234/2012 - Charles Goerens - Résolution", "title": "A7-0234/2012 - Charles Goerens - Résolution",
"description": "", "description": "",
...@@ -28,15 +34,11 @@ ...@@ -28,15 +34,11 @@
], ],
"documents": [ "documents": [
{ {
"id": 1,
"dossier": "http://testserver/api/dossiers/1/", "dossier": "http://testserver/api/dossiers/1/",
"chamber": "http://testserver/api/chambers/1/", "chamber": "http://testserver/api/chambers/1/",
"kind": "procedure-file", "kind": "procedure-file",
"link": "http://www.europarl.europa.eu/oeil/popups/ficheprocedure.do?reference=2012/2002(INI)" "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
[ [
{ {
"id": 1,
"url": "http://testserver/api/dossiers/1/",
"title": "Agenda for change: the future of EU development policy", "title": "Agenda for change: the future of EU development policy",
"reference": "2012/2002(INI)", "reference": "2012/2002(INI)",
"text": "", "text": ""
"url": "http://testserver/api/dossiers/1/"
}, },
{ {
"id": 2,
"url": "http://testserver/api/dossiers/2/",
"title": "2016 general budget: all sections", "title": "2016 general budget: all sections",
"reference": "2015/2132(BUD)", "reference": "2015/2132(BUD)",
"text": "", "text": ""
"url": "http://testserver/api/dossiers/2/"
} }
] ]
\ No newline at end of file
{ {
"id": 1,
"dossier": "http://testserver/api/dossiers/1/", "dossier": "http://testserver/api/dossiers/1/",
"title": "A7-0234/2012 - Charles Goerens - § 31", "title": "A7-0234/2012 - Charles Goerens - § 31",
"description": "", "description": "",
...@@ -13,13 +14,11 @@ ...@@ -13,13 +14,11 @@
{ {
"proposal": "http://testserver/api/proposals/1/", "proposal": "http://testserver/api/proposals/1/",
"representative": "http://testserver/api/representatives/2/", "representative": "http://testserver/api/representatives/2/",
"representative_name": "",
"position": "abstain" "position": "abstain"
}, },
{ {
"proposal": "http://testserver/api/proposals/1/", "proposal": "http://testserver/api/proposals/1/",
"representative": "http://testserver/api/representatives/1/", "representative": "http://testserver/api/representatives/1/",
"representative_name": "",
"position": "abstain" "position": "abstain"
} }
] ]
......
[ [
{ {
"id": 1,
"dossier": "http://testserver/api/dossiers/1/", "dossier": "http://testserver/api/dossiers/1/",
"title": "A7-0234/2012 - Charles Goerens - § 31", "title": "A7-0234/2012 - Charles Goerens - § 31",
"description": "", "description": "",
...@@ -12,6 +13,7 @@ ...@@ -12,6 +13,7 @@
"url": "http://testserver/api/proposals/1/" "url": "http://testserver/api/proposals/1/"
}, },
{ {
"id": 2,
"dossier": "http://testserver/api/dossiers/1/", "dossier": "http://testserver/api/dossiers/1/",
"title": "A7-0234/2012 - Charles Goerens - Résolution", "title": "A7-0234/2012 - Charles Goerens - Résolution",
"description": "", "description": "",
...@@ -24,6 +26,7 @@ ...@@ -24,6 +26,7 @@
"url": "http://testserver/api/proposals/2/" "url": "http://testserver/api/proposals/2/"
}, },
{ {
"id": 3,
"dossier": "http://testserver/api/dossiers/2/", "dossier": "http://testserver/api/dossiers/2/",
"title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 4", "title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 4",
"description": "", "description": "",
...@@ -36,6 +39,7 @@ ...@@ -36,6 +39,7 @@
"url": "http://testserver/api/proposals/3/" "url": "http://testserver/api/proposals/3/"
}, },
{ {
"id": 4,
"dossier": "http://testserver/api/dossiers/2/", "dossier": "http://testserver/api/dossiers/2/",
"title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 29", "title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 29",
"description": "", "description": "",
...@@ -48,6 +52,7 @@ ...@@ -48,6 +52,7 @@
"url": "http://testserver/api/proposals/4/" "url": "http://testserver/api/proposals/4/"
}, },
{ {
"id": 5,
"dossier": "http://testserver/api/dossiers/2/", "dossier": "http://testserver/api/dossiers/2/",
"title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 31", "title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 31",
"description": "", "description": "",
...@@ -60,6 +65,7 @@ ...@@ -60,6 +65,7 @@
"url": "http://testserver/api/proposals/5/" "url": "http://testserver/api/proposals/5/"
}, },
{ {
"id": 6,
"dossier": "http://testserver/api/dossiers/2/", "dossier": "http://testserver/api/dossiers/2/",
"title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 30", "title": "A8-0298/2015 - José Manuel Fernandes et Gérard Deprez - Am 30",
"description": "", "description": "",
......
{ {
"proposal": "http://testserver/api/proposals/1/", "proposal": "http://testserver/api/proposals/1/",
"representative": "http://testserver/api/representatives/2/", "representative": "http://testserver/api/representatives/2/",
"representative_name": "",
"position": "abstain" "position": "abstain"
} }
\ No newline at end of file
...@@ -2,67 +2,56 @@ ...@@ -2,67 +2,56 @@
{ {
"proposal": "http://testserver/api/proposals/1/", "proposal": "http://testserver/api/proposals/1/",
"representative": "http://testserver/api/representatives/2/", "representative": "http://testserver/api/representatives/2/",
"representative_name": "",
"position": "abstain" "position": "abstain"
}, },
{ {
"proposal": "http://testserver/api/proposals/1/", "proposal": "http://testserver/api/proposals/1/",
"representative": "http://testserver/api/representatives/1/", "representative": "http://testserver/api/representatives/1/",
"representative_name": "",
"position": "abstain" "position": "abstain"
}, },
{ {
"proposal": "http://testserver/api/proposals/2/", "proposal": "http://testserver/api/proposals/2/",
"representative": "http://testserver/api/representatives/2/", "representative": "http://testserver/api/representatives/2/",
"representative_name": "",
"position": "for" "position": "for"
}, },
{ {
"proposal": "http://testserver/api/proposals/2/", "proposal": "http://testserver/api/proposals/2/",
"representative": "http://testserver/api/representatives/1/", "representative": "http://testserver/api/representatives/1/",
"representative_name": "",
"position": "for" "position": "for"
}, },
{ {
"proposal": "http://testserver/api/proposals/3/", "proposal": "http://testserver/api/proposals/3/",
"representative": "http://testserver/api/representatives/2/", "representative": "http://testserver/api/representatives/2/",
"representative_name": "",
"position": "against" "position": "against"
}, },
{ {
"proposal": "http://testserver/api/proposals/3/", "proposal": "http://testserver/api/proposals/3/",
"representative": "http://testserver/api/representatives/1/", "representative": "http://testserver/api/representatives/1/",
"representative_name": "",
"position": "against" "position": "against"
}, },
{ {
"proposal": "http://testserver/api/proposals/4/", "proposal": "http://testserver/api/proposals/4/",
"representative": "http://testserver/api/representatives/1/", "representative": "http://testserver/api/representatives/1/",
"representative_name": "",
"position": "for" "position": "for"
}, },
{ {
"proposal": "http://testserver/api/proposals/4/", "proposal": "http://testserver/api/proposals/4/",
"representative": "http://testserver/api/representatives/2/", "representative": "http://testserver/api/representatives/2/",
"representative_name": "",
"position": "against" "position": "against"
}, },
{ {
"proposal": "http://testserver/api/proposals/5/", "proposal": "http://testserver/api/proposals/5/",
"representative": "http://testserver/api/representatives/1/", "representative": "http://testserver/api/representatives/1/",
"representative_name": "",
"position": "abstain" "position": "abstain"
}, },
{ {
"proposal": "http://testserver/api/proposals/5/", "proposal": "http://testserver/api/proposals/5/",
"representative": "http://testserver/api/representatives/2/", "representative": "http://testserver/api/representatives/2/",
"representative_name": "",
"position": "against" "position": "against"
}, },
{ {
"proposal": "http://testserver/api/proposals/6/", "proposal": "http://testserver/api/proposals/6/",
"representative": "http://testserver/api/representatives/1/", "representative": "http://testserver/api/representatives/1/",
"representative_name": "",
"position": "for" "position": "for"
} }
] ]
\ No newline at end of file
...@@ -11,21 +11,23 @@ from representatives_votes.api import ( ...@@ -11,21 +11,23 @@ from representatives_votes.api import (
from representatives.api import ( from representatives.api import (
ChamberViewSet, ChamberViewSet,
ConstituencyViewSet, ConstituencyViewSet,
CountryViewSet,
GroupViewSet, GroupViewSet,
MandateViewSet, MandateViewSet,
RepresentativeViewSet, RepresentativeViewSet,
) )
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'chambers', ChamberViewSet) router.register('countries', CountryViewSet, 'api-country')
router.register(r'constituencies', ConstituencyViewSet) router.register('chambers', ChamberViewSet, 'api-chamber')
router.register(r'groups', GroupViewSet) router.register('constituencies', ConstituencyViewSet, 'api-constituency')
router.register(r'mandates', MandateViewSet) router.register('groups', GroupViewSet, 'api-group')
router.register(r'representatives', RepresentativeViewSet) router.register('mandates', MandateViewSet, 'api-mandate')
router.register(r'dossiers', DossierViewSet) router.register('representatives', RepresentativeViewSet, 'api-representative')
router.register(r'proposals', ProposalViewSet) router.register('dossiers', DossierViewSet, 'api-dossier')
router.register(r'votes', VoteViewSet) router.register('proposals', ProposalViewSet, 'api-proposal')
router.register('votes', VoteViewSet, 'api-vote')
urlpatterns = [ urlpatterns = [
url(r'api/', include(router.urls)), url('api/', include(router.urls)),
] ]
...@@ -13,7 +13,7 @@ setup( ...@@ -13,7 +13,7 @@ setup(
keywords='django government parliament votes', keywords='django government parliament votes',
install_requires=[ install_requires=[
'django>1.8,<1.9', 'django>1.8,<1.9',
'django-representatives>=0.0.32', 'django-representatives>=0.0.33',
'py-dateutil>=2,<3', 'py-dateutil>=2,<3',
'ijson>=2,<3', 'ijson>=2,<3',
'pytz', # Always use up-to-date TZ data 'pytz', # Always use up-to-date TZ data
......
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