Commit 64804481 authored by Nicolas Joyard's avatar Nicolas Joyard

Fix API inconsistencies

parent 45616b4e
......@@ -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')
{
"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
[
{
"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
{
"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"
}
]
......
[
{
"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": "",
......
{
"proposal": "http://testserver/api/proposals/1/",
"representative": "http://testserver/api/representatives/2/",
"representative_name": "",
"position": "abstain"
}
\ No newline at end of file
......@@ -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
......@@ -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)),
]
......@@ -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
......
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