Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
memopol
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
32
Issues
32
List
Boards
Labels
Service Desk
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Political Memory
memopol
Commits
394fbec7
Commit
394fbec7
authored
May 14, 2016
by
Nicolas Joyard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add scores, scoredvotes, recommendations to api
parent
7d05cdc8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
134 additions
and
0 deletions
+134
-0
memopol/api.py
memopol/api.py
+10
-0
representatives_recommendations/api.py
representatives_recommendations/api.py
+87
-0
representatives_recommendations/serializers.py
representatives_recommendations/serializers.py
+37
-0
No files found.
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
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