Skip to content
GitLab
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
394fbec7
Commit
394fbec7
authored
May 14, 2016
by
Nicolas Joyard
Browse files
Add scores, scoredvotes, recommendations to api
parent
7d05cdc8
Changes
3
Hide whitespace changes
Inline
Side-by-side
memopol/api.py
View file @
394fbec7
...
...
@@ -13,6 +13,13 @@ from representatives_votes.api import (
VoteViewSet
,
)
from
representatives_recommendations.api
import
(
RecommendationViewSet
,
RepresentativeScoreViewSet
,
ScoredVoteViewSet
)
router
=
routers
.
DefaultRouter
()
router
.
register
(
r
'constituencies'
,
ConstituencyViewSet
)
...
...
@@ -20,5 +27,8 @@ router.register(r'dossiers', DossierViewSet)
router
.
register
(
r
'groups'
,
GroupViewSet
)
router
.
register
(
r
'mandates'
,
MandateViewSet
)
router
.
register
(
r
'proposals'
,
ProposalViewSet
)
router
.
register
(
r
'recommendations'
,
RecommendationViewSet
)
router
.
register
(
r
'representatives'
,
RepresentativeViewSet
)
router
.
register
(
r
'scores'
,
RepresentativeScoreViewSet
)
router
.
register
(
r
'scored_votes'
,
ScoredVoteViewSet
)
router
.
register
(
r
'votes'
,
VoteViewSet
)
representatives_recommendations/api.py
0 → 100644
View file @
394fbec7
from
rest_framework
import
(
filters
,
viewsets
,
)
from
representatives.api
import
DefaultWebPagination
from
.models
import
(
Recommendation
,
RepresentativeScore
,
ScoredVote
)
from
.serializers
import
(
RecommendationSerializer
,
RepresentativeScoreSerializer
,
ScoredVoteSerializer
)
class
RecommendationViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
"""
API endpoint that allows recommendations to be viewed.
"""
queryset
=
Recommendation
.
objects
.
select_related
(
'proposal'
)
filter_backends
=
(
filters
.
DjangoFilterBackend
,
filters
.
SearchFilter
,
filters
.
OrderingFilter
)
filter_fields
=
{
'id'
:
[
'exact'
],
'recommendation'
:
[
'exact'
],
'title'
:
[
'exact'
,
'icontains'
],
'description'
:
[
'exact'
,
'icontains'
],
'weight'
:
[
'exact'
,
'gte'
,
'lte'
]
}
search_fields
=
(
'title'
,
'description'
)
ordering_fields
=
(
'id'
,
'weight'
,
'title'
)
pagination_class
=
DefaultWebPagination
serializer_class
=
RecommendationSerializer
class
RepresentativeScoreViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
"""
API endpoint to view representative scores
"""
queryset
=
RepresentativeScore
.
objects
.
select_related
(
'representative'
)
filter_backends
=
(
filters
.
DjangoFilterBackend
,
filters
.
SearchFilter
,
filters
.
OrderingFilter
)
filter_fields
=
{
'representative'
:
[
'exact'
],
'score'
:
[
'exact'
,
'gte'
,
'lte'
]
}
search_fields
=
(
'representative'
,
'score'
)
ordering_fields
=
(
'representative'
,
'score'
)
pagination_class
=
DefaultWebPagination
serializer_class
=
RepresentativeScoreSerializer
class
ScoredVoteViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
"""
API endpoint to view votes with their score impact.
This endpoint only shows votes that have a matching recommendation.
"""
queryset
=
ScoredVote
.
objects
.
select_related
(
'representative'
,
'proposal'
,
'proposal__recommendation'
).
filter
(
proposal__recommendation__isnull
=
False
)
filter_backends
=
(
filters
.
DjangoFilterBackend
,
filters
.
SearchFilter
,
filters
.
OrderingFilter
)
filter_fields
=
{
}
pagination_class
=
DefaultWebPagination
serializer_class
=
ScoredVoteSerializer
representatives_recommendations/serializers.py
0 → 100644
View file @
394fbec7
from
rest_framework
import
serializers
from
.models
import
(
Recommendation
,
RepresentativeScore
,
ScoredVote
)
class
RecommendationSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
Recommendation
fields
=
(
'recommendation'
,
'title'
,
'description'
,
'weight'
,
'proposal'
)
class
RepresentativeScoreSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
RepresentativeScore
fields
=
(
'representative'
,
'score'
)
class
ScoredVoteSerializer
(
serializers
.
HyperlinkedModelSerializer
):
"""
Scored Vote serializer
"""
class
Meta
:
model
=
ScoredVote
fields
=
(
'proposal'
,
'representative'
,
'position'
,
'absolute_score'
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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