Commit 5d1bf519 authored by Nicolas Joyard's avatar Nicolas Joyard

Use RQLFilterBackend; show mandates in rep list

parent 4639bd42
......@@ -7,6 +7,8 @@ from rest_framework import (
viewsets,
)
from rql_filter.backend import RQLFilterBackend
from representatives.serializers import (
ChamberSerializer,
ConstituencySerializer,
......@@ -51,7 +53,8 @@ class RepresentativeViewSet(viewsets.ReadOnlyModelViewSet):
filter_backends = (
filters.DjangoFilterBackend,
filters.SearchFilter,
filters.OrderingFilter
filters.OrderingFilter,
RQLFilterBackend
)
filter_fields = {
'active': ['exact'],
......@@ -105,7 +108,8 @@ class MandateViewSet(viewsets.ReadOnlyModelViewSet):
filter_backends = (
filters.DjangoFilterBackend,
filters.SearchFilter,
filters.OrderingFilter
filters.OrderingFilter,
RQLFilterBackend
)
filter_fields = {
'id': ['exact'],
......@@ -120,20 +124,36 @@ class ConstituencyViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Constituency.objects.all()
serializer_class = ConstituencySerializer
filter_backends = (
RQLFilterBackend,
)
class GroupViewSet(viewsets.ReadOnlyModelViewSet):
pagination_class = DefaultWebPagination
queryset = Group.objects.all()
serializer_class = GroupSerializer
filter_backends = (
RQLFilterBackend,
)
class ChamberViewSet(viewsets.ReadOnlyModelViewSet):
pagination_class = DefaultWebPagination
queryset = Chamber.objects.all()
serializer_class = ChamberSerializer
filter_backends = (
RQLFilterBackend,
)
class CountryViewSet(viewsets.ReadOnlyModelViewSet):
pagination_class = DefaultWebPagination
queryset = Country.objects.all()
serializer_class = CountrySerializer
filter_backends = (
RQLFilterBackend,
)
......@@ -156,6 +156,8 @@ class MandateDetailSerializer(MandateSerializer):
class RepresentativeSerializer(serializers.HyperlinkedModelSerializer):
contacts = ContactField()
mandates = MandateDetailSerializer(many=True)
class Meta:
model = models.Representative
fields = (
......@@ -172,6 +174,7 @@ class RepresentativeSerializer(serializers.HyperlinkedModelSerializer):
'active',
'cv',
'contacts',
'mandates'
)
extra_kwargs = {
'url': {'view_name': 'api-representative-detail'},
......@@ -179,10 +182,4 @@ class RepresentativeSerializer(serializers.HyperlinkedModelSerializer):
class RepresentativeDetailSerializer(RepresentativeSerializer):
mandates = MandateDetailSerializer(many=True)
class Meta(RepresentativeSerializer.Meta):
fields = RepresentativeSerializer.Meta.fields + (
'mandates',
)
pass
[{"id":2,"url":"http://testserver/api/representatives/2/?format=json","slug":"olle-ludvigsson-1948-10-28","first_name":"Olle","last_name":"LUDVIGSSON","full_name":"Olle LUDVIGSSON","gender":2,"birth_place":"Hälsö","birth_date":"1948-10-28","photo":"http://www.europarl.europa.eu/mepphoto/96673.jpg","active":true,"cv":"","contacts":{"emails":[{"email":"olle.ludvigsson@europarl.europa.eu","kind":"official"}],"phones":[{"number":"+322 28 45442","kind":"office phone"},{"number":"+333 88 1 75442","kind":"office phone"}],"websites":[{"url":"http://www.sap.se/olle","kind":""},{"url":"http://twitter.com/olleludvigsson","kind":"twitter"},{"url":"https://www.facebook.com/olle.ludvigsson","kind":"facebook"},{"url":"http://www.europarl.europa.eu/meps/en/96673/_home.html","kind":"EP"}],"address":[{"country":{"id":1050,"url":"http://testserver/api/countries/1050/?format=json","name":"Belgium","code":"BE"},"city":"Brussels","street":"rue Wiertz / Wiertzstraat","number":"60","postcode":"1047","floor":"14G","office_number":"257","kind":"official"},{"country":{"id":1095,"url":"http://testserver/api/countries/1095/?format=json","name":"France","code":"FR"},"city":"Strasbourg","street":"Av. du Président Robert Schuman - CS 91024","number":"1","postcode":"67070","floor":"T07","office_number":"070","kind":"official"}]}},{"id":1,"url":"http://testserver/api/representatives/1/?format=json","slug":"hubert-pirker-1948-10-03","first_name":"Hubert","last_name":"PIRKER","full_name":"Hubert PIRKER","gender":2,"birth_place":"Gries","birth_date":"1948-10-03","photo":"http://www.europarl.europa.eu/mepphoto/2307.jpg","active":false,"cv":"Transport and security spokesman, ÖVP Delegation, European Parliament;\nsecurity spokesman, ÖVP Delegation, European Parliament (2006-2009); security spokesman (coordinator), EPP Group (1999-2004); Deputy Head of ÖVP Delegation, European Parliament (1996-2004);","contacts":{"emails":[],"phones":[],"websites":[{"url":"http://www.europarl.europa.eu/meps/en/2307/_home.html","kind":"EP"}],"address":[]}}]
\ No newline at end of file
[{"id":2,"url":"http://testserver/api/representatives/2/?format=json","slug":"olle-ludvigsson-1948-10-28","first_name":"Olle","last_name":"LUDVIGSSON","full_name":"Olle LUDVIGSSON","gender":2,"birth_place":"Hälsö","birth_date":"1948-10-28","photo":"http://www.europarl.europa.eu/mepphoto/96673.jpg","active":true,"cv":"","contacts":{"emails":[{"email":"olle.ludvigsson@europarl.europa.eu","kind":"official"}],"phones":[{"number":"+322 28 45442","kind":"office phone"},{"number":"+333 88 1 75442","kind":"office phone"}],"websites":[{"url":"http://www.sap.se/olle","kind":""},{"url":"http://twitter.com/olleludvigsson","kind":"twitter"},{"url":"https://www.facebook.com/olle.ludvigsson","kind":"facebook"},{"url":"http://www.europarl.europa.eu/meps/en/96673/_home.html","kind":"EP"}],"address":[{"country":{"id":1050,"url":"http://testserver/api/countries/1050/?format=json","name":"Belgium","code":"BE"},"city":"Brussels","street":"rue Wiertz / Wiertzstraat","number":"60","postcode":"1047","floor":"14G","office_number":"257","kind":"official"},{"country":{"id":1095,"url":"http://testserver/api/countries/1095/?format=json","name":"France","code":"FR"},"city":"Strasbourg","street":"Av. du Président Robert Schuman - CS 91024","number":"1","postcode":"67070","floor":"T07","office_number":"070","kind":"official"}]},"mandates":[{"id":9,"url":"http://testserver/api/mandates/9/?format=json","group":{"id":8,"url":"http://testserver/api/groups/8/?format=json","name":"Committee on Economic and Monetary Affairs","abbreviation":"ECON","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2014-07-01","end_date":"9999-12-31"},{"id":10,"url":"http://testserver/api/mandates/10/?format=json","group":{"id":9,"url":"http://testserver/api/groups/9/?format=json","name":"Committee on Industry, Research and Energy","abbreviation":"ITRE","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2014-07-08","end_date":"9999-12-31"},{"id":12,"url":"http://testserver/api/mandates/12/?format=json","group":{"id":10,"url":"http://testserver/api/groups/10/?format=json","name":"Delegation to the EU-Serbia Stabilisation and Association Parliamentary Committee","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2014-07-14","end_date":"9999-12-31"},{"id":13,"url":"http://testserver/api/mandates/13/?format=json","group":{"id":11,"url":"http://testserver/api/groups/11/?format=json","name":"Delegation for relations with Bosnia and Herzegovina, and Kosovo","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2015-05-18","end_date":"9999-12-31"},{"id":15,"url":"http://testserver/api/mandates/15/?format=json","group":{"id":13,"url":"http://testserver/api/groups/13/?format=json","name":"Group of the Progressive Alliance of Socialists and Democrats in the European Parliament","abbreviation":"SD","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2014-07-01","end_date":"9999-12-31"},{"id":17,"url":"http://testserver/api/mandates/17/?format=json","group":{"id":14,"url":"http://testserver/api/groups/14/?format=json","name":"Sweden","abbreviation":"SE","kind":"country"},"constituency":{"id":3,"url":"http://testserver/api/constituencies/3/?format=json","name":"Arbetarepartiet- Socialdemokraterna"},"role":"","begin_date":"2014-07-01","end_date":"9999-12-31"},{"id":16,"url":"http://testserver/api/mandates/16/?format=json","group":{"id":13,"url":"http://testserver/api/groups/13/?format=json","name":"Group of the Progressive Alliance of Socialists and Democrats in the European Parliament","abbreviation":"SD","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2009-07-14","end_date":"2014-06-30"},{"id":18,"url":"http://testserver/api/mandates/18/?format=json","group":{"id":14,"url":"http://testserver/api/groups/14/?format=json","name":"Sweden","abbreviation":"SE","kind":"country"},"constituency":{"id":3,"url":"http://testserver/api/constituencies/3/?format=json","name":"Arbetarepartiet- Socialdemokraterna"},"role":"","begin_date":"2009-07-14","end_date":"2014-06-30"},{"id":14,"url":"http://testserver/api/mandates/14/?format=json","group":{"id":12,"url":"http://testserver/api/groups/12/?format=json","name":"Delegation for relations with Australia and New Zealand","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2009-09-17","end_date":"2013-01-10"},{"id":11,"url":"http://testserver/api/mandates/11/?format=json","group":{"id":8,"url":"http://testserver/api/groups/8/?format=json","name":"Committee on Economic and Monetary Affairs","abbreviation":"ECON","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"2009-07-16","end_date":"2012-01-18"}]},{"id":1,"url":"http://testserver/api/representatives/1/?format=json","slug":"hubert-pirker-1948-10-03","first_name":"Hubert","last_name":"PIRKER","full_name":"Hubert PIRKER","gender":2,"birth_place":"Gries","birth_date":"1948-10-03","photo":"http://www.europarl.europa.eu/mepphoto/2307.jpg","active":false,"cv":"Transport and security spokesman, ÖVP Delegation, European Parliament;\nsecurity spokesman, ÖVP Delegation, European Parliament (2006-2009); security spokesman (coordinator), EPP Group (1999-2004); Deputy Head of ÖVP Delegation, European Parliament (1996-2004);","contacts":{"emails":[],"phones":[],"websites":[{"url":"http://www.europarl.europa.eu/meps/en/2307/_home.html","kind":"EP"}],"address":[]},"mandates":[{"id":2,"url":"http://testserver/api/mandates/2/?format=json","group":{"id":2,"url":"http://testserver/api/groups/2/?format=json","name":"Delegation for relations with the countries of Southeast Asia and the Association of Southeast Asian Nations (ASEAN)","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2013-10-09","end_date":"2014-06-30"},{"id":8,"url":"http://testserver/api/mandates/8/?format=json","group":{"id":7,"url":"http://testserver/api/groups/7/?format=json","name":"Conference of Delegation Chairs","abbreviation":"","kind":"organization"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"2006-03-21","end_date":"2009-07-13"},{"id":4,"url":"http://testserver/api/mandates/4/?format=json","group":{"id":4,"url":"http://testserver/api/groups/4/?format=json","name":"Group of the European People's Party (Christian Democrats) and European Democrats","abbreviation":"PPE-DE","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"1999-07-20","end_date":"2004-07-19"},{"id":6,"url":"http://testserver/api/mandates/6/?format=json","group":{"id":6,"url":"http://testserver/api/groups/6/?format=json","name":"Austria","abbreviation":"AT","kind":"country"},"constituency":{"id":2,"url":"http://testserver/api/constituencies/2/?format=json","name":"Österreichische Volkspartei"},"role":"","begin_date":"1999-07-20","end_date":"2004-07-19"},{"id":1,"url":"http://testserver/api/mandates/1/?format=json","group":{"id":1,"url":"http://testserver/api/groups/1/?format=json","name":"Committee on Employment and Social Affairs","abbreviation":"EMPL","kind":"committee"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Substitute","begin_date":"1997-01-16","end_date":"1999-07-19"},{"id":5,"url":"http://testserver/api/mandates/5/?format=json","group":{"id":5,"url":"http://testserver/api/groups/5/?format=json","name":"Group of the European People's Party (Christian-Democratic Group)","abbreviation":"EPP","kind":"group"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"1996-11-11","end_date":"1999-07-19"},{"id":7,"url":"http://testserver/api/mandates/7/?format=json","group":{"id":6,"url":"http://testserver/api/groups/6/?format=json","name":"Austria","abbreviation":"AT","kind":"country"},"constituency":{"id":2,"url":"http://testserver/api/constituencies/2/?format=json","name":"Österreichische Volkspartei"},"role":"","begin_date":"1996-11-11","end_date":"1999-07-19"},{"id":3,"url":"http://testserver/api/mandates/3/?format=json","group":{"id":3,"url":"http://testserver/api/groups/3/?format=json","name":"Delegation for relations with the Member States of ASEAN, South-east Asia and the Republic of Korea","abbreviation":"","kind":"delegation"},"constituency":{"id":1,"url":"http://testserver/api/constituencies/1/?format=json","name":"European Parliament"},"role":"Member","begin_date":"1996-11-14","end_date":"1997-01-15"}]}]
\ No newline at end of file
......@@ -19,6 +19,7 @@ setup(
'celery': 'celery',
'api': [
'django-filter>=0.13,<0.14',
'django-rql-filter>=0.1.3,<0.2',
'djangorestframework>=3,<4',
],
'testing': [
......
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