Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Political Memory
memopol
Commits
822034dc
Commit
822034dc
authored
Oct 09, 2016
by
Nicolas Joyard
Browse files
Add themes + theme scores to API, fixes #163
parent
13c1b7e1
Pipeline
#162
passed with stages
in 24 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/memopol/api.py
View file @
822034dc
...
...
@@ -21,9 +21,14 @@ from representatives_recommendations.api import (
RecommendationViewSet
)
from
memopol_themes.api
import
(
ThemeViewSet
)
from
memopol_scores.api
import
(
DossierScoreViewSet
,
RepresentativeScoreViewSet
,
ThemeScoreViewSet
,
VoteScoreViewSet
)
...
...
@@ -54,5 +59,7 @@ router.register('recommendations', RecommendationViewSet, 'api-recommendation')
router
.
register
(
'representatives'
,
RepresentativeViewSet
,
'api-representative'
)
router
.
register
(
'scores'
,
RepresentativeScoreViewSet
,
'api-score'
)
router
.
register
(
'theme_scores'
,
ThemeScoreViewSet
,
'api-themescore'
)
router
.
register
(
'themes'
,
ThemeViewSet
,
'api-themes'
)
router
.
register
(
'vote_scores'
,
VoteScoreViewSet
,
'api-votescore'
)
router
.
register
(
'votes'
,
RQLVoteViewSet
,
'api-vote'
)
src/memopol_scores/api.py
View file @
822034dc
...
...
@@ -10,12 +10,14 @@ from representatives.api import DefaultWebPagination
from
.models
import
(
DossierScore
,
RepresentativeScore
,
ThemeScore
,
VoteScore
)
from
.serializers
import
(
DossierScoreSerializer
,
RepresentativeScoreSerializer
,
ThemeScoreSerializer
,
VoteScoreSerializer
)
...
...
@@ -63,6 +65,28 @@ class RepresentativeScoreViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class
=
RepresentativeScoreSerializer
class
ThemeScoreViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
"""
API endpoint to view theme scores
"""
queryset
=
ThemeScore
.
objects
.
select_related
(
'representative'
,
'theme'
)
filter_backends
=
(
filters
.
DjangoFilterBackend
,
filters
.
SearchFilter
,
filters
.
OrderingFilter
,
RQLFilterBackend
)
filter_fields
=
{
'representative'
:
[
'exact'
],
'theme'
:
[
'exact'
],
'score'
:
[
'exact'
,
'gte'
,
'lte'
]
}
search_fields
=
(
'representative'
,
'theme'
,
'score'
)
ordering_fields
=
(
'representative'
,
'theme'
,
'score'
)
pagination_class
=
DefaultWebPagination
serializer_class
=
ThemeScoreSerializer
class
VoteScoreViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
"""
API endpoint to view votes with their score impact.
...
...
src/memopol_scores/serializers.py
View file @
822034dc
from
rest_framework
import
serializers
from
memopol_themes.serializers
import
ThemeSerializer
from
representatives.serializers
import
RepresentativeSimpleSerializer
from
.models
import
(
DossierScore
,
RepresentativeScore
,
ThemeScore
,
VoteScore
)
...
...
@@ -28,6 +32,15 @@ class RepresentativeScoreSerializer(serializers.HyperlinkedModelSerializer):
}
class
ThemeScoreSerializer
(
serializers
.
HyperlinkedModelSerializer
):
theme
=
ThemeSerializer
()
representative
=
RepresentativeSimpleSerializer
()
class
Meta
:
model
=
ThemeScore
fields
=
(
'representative'
,
'theme'
,
'score'
)
class
VoteScoreSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
...
...
src/memopol_themes/api.py
0 → 100644
View file @
822034dc
from
rest_framework
import
(
filters
,
viewsets
,
)
from
representatives.api
import
DefaultWebPagination
from
rql_filter.backend
import
RQLFilterBackend
from
.models
import
Theme
from
.serializers
import
ThemeSerializer
class
ThemeViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
"""
API endpoint to view themes
"""
queryset
=
Theme
.
objects
.
all
()
filter_backends
=
(
filters
.
SearchFilter
,
filters
.
OrderingFilter
,
RQLFilterBackend
)
search_fields
=
(
'name'
,)
ordering_fields
=
(
'name'
,)
pagination_class
=
DefaultWebPagination
serializer_class
=
ThemeSerializer
src/memopol_themes/serializers.py
0 → 100644
View file @
822034dc
from
rest_framework
import
serializers
from
.models
import
Theme
class
ThemeSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
Theme
fields
=
(
'name'
,)
src/representatives/serializers.py
View file @
822034dc
...
...
@@ -153,6 +153,20 @@ class MandateDetailSerializer(MandateSerializer):
)
class
RepresentativeSimpleSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
models
.
Representative
fields
=
(
'id'
,
'url'
,
'first_name'
,
'last_name'
)
extra_kwargs
=
{
'url'
:
{
'view_name'
:
'api-representative-detail'
},
}
class
RepresentativeSerializer
(
serializers
.
HyperlinkedModelSerializer
):
contacts
=
ContactField
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment