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
ae8a230a
Commit
ae8a230a
authored
Jan 27, 2016
by
James Pic
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12 from political-memory/api
API release
parents
eebec1ea
842da8b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
40 deletions
+43
-40
representatives_votes/api.py
representatives_votes/api.py
+33
-10
representatives_votes/serializers.py
representatives_votes/serializers.py
+10
-30
No files found.
representatives_votes/api.py
View file @
ae8a230a
...
...
@@ -26,7 +26,11 @@ class DossierViewSet(viewsets.ReadOnlyModelViewSet):
queryset
=
Dossier
.
objects
.
all
()
serializer_class
=
DossierSerializer
filter_backends
=
(
filters
.
DjangoFilterBackend
,
filters
.
SearchFilter
,
filters
.
OrderingFilter
)
filter_backends
=
(
filters
.
DjangoFilterBackend
,
filters
.
SearchFilter
,
filters
.
OrderingFilter
)
filter_fields
=
{
'fingerprint'
:
[
'exact'
],
...
...
@@ -34,9 +38,15 @@ class DossierViewSet(viewsets.ReadOnlyModelViewSet):
'reference'
:
[
'exact'
,
'icontains'
],
}
search_fields
=
(
'title'
,
'fingerprint'
,
'reference'
,
'text'
,
'proposals__title'
)
ordering_fields
=
(
'id'
,
'reference'
)
search_fields
=
(
'title'
,
'fingerprint'
,
'reference'
,
'text'
,
'proposals__title'
)
ordering_fields
=
(
'id'
,
'reference'
)
def
list
(
self
,
request
):
return
super
(
DossierViewSet
,
self
).
list
(
request
)
...
...
@@ -51,10 +61,14 @@ class ProposalViewSet(viewsets.ReadOnlyModelViewSet):
API endpoint that allows proposals to be viewed.
"""
queryset
=
Proposal
.
objects
.
all
(
)
queryset
=
Proposal
.
objects
.
select_related
(
'dossier'
)
serializer_class
=
ProposalSerializer
filter_backends
=
(
filters
.
DjangoFilterBackend
,
filters
.
SearchFilter
,
filters
.
OrderingFilter
)
filter_backends
=
(
filters
.
DjangoFilterBackend
,
filters
.
SearchFilter
,
filters
.
OrderingFilter
)
filter_fields
=
{
'fingerprint'
:
[
'exact'
],
...
...
@@ -66,9 +80,14 @@ class ProposalViewSet(viewsets.ReadOnlyModelViewSet):
'kind'
:
[
'exact'
],
}
search_fields
=
(
'title'
,
'fingerprint'
,
'reference'
,
'dossier__fingerprint'
,
'dossier__title'
,
'dossier__reference'
)
search_fields
=
(
'title'
,
'fingerprint'
,
'reference'
,
'dossier__fingerprint'
,
'dossier__title'
,
'dossier__reference'
)
ordering_fields
=
(
'id'
,
'reference'
)
def
list
(
self
,
request
):
...
...
@@ -84,10 +103,14 @@ class VoteViewSet(viewsets.ReadOnlyModelViewSet):
API endpoint that allows proposals to be viewed.
"""
queryset
=
Vote
.
objects
.
all
(
)
queryset
=
Vote
.
objects
.
select_related
(
'representative'
,
'proposal'
)
serializer_class
=
VoteSerializer
filter_backends
=
(
filters
.
DjangoFilterBackend
,
filters
.
SearchFilter
,
filters
.
OrderingFilter
)
filter_backends
=
(
filters
.
DjangoFilterBackend
,
filters
.
SearchFilter
,
filters
.
OrderingFilter
)
filter_fields
=
{
'proposal__fingerprint'
:
[
'exact'
],
...
...
representatives_votes/serializers.py
View file @
ae8a230a
# coding: utf-8
# This file is part of toutatis.
#
# toutatis is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# toutatis is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
import
representatives_votes.models
as
models
from
representatives.models
import
Representative
from
rest_framework
import
serializers
...
...
@@ -34,7 +16,7 @@ class VoteSerializer(serializers.ModelSerializer):
source
=
'representative.fingerprint'
,
allow_null
=
True
)
class
Meta
:
model
=
models
.
Vote
fields
=
(
...
...
@@ -74,7 +56,7 @@ class ProposalSerializer(serializers.ModelSerializer):
source
=
'dossier.reference'
,
read_only
=
True
)
class
Meta
:
model
=
models
.
Proposal
fields
=
(
...
...
@@ -95,13 +77,14 @@ class ProposalSerializer(serializers.ModelSerializer):
)
def
to_internal_value
(
self
,
data
):
validated_data
=
super
(
ProposalSerializer
,
self
).
to_internal_value
(
data
)
validated_data
=
super
(
ProposalSerializer
,
self
).
to_internal_value
(
data
)
validated_data
[
'dossier'
]
=
models
.
Dossier
.
objects
.
get
(
fingerprint
=
validated_data
[
'dossier'
][
'fingerprint'
]
)
validated_data
[
'votes'
]
=
data
[
'votes'
]
return
validated_data
def
_create_votes
(
self
,
votes_data
,
proposal
):
for
vote
in
votes_data
:
serializer
=
VoteSerializer
(
data
=
vote
)
...
...
@@ -109,7 +92,7 @@ class ProposalSerializer(serializers.ModelSerializer):
serializer
.
save
()
else
:
raise
Exception
(
serializer
.
errors
)
def
create
(
self
,
validated_data
):
votes_data
=
validated_data
.
pop
(
'votes'
)
proposal
=
models
.
Proposal
.
objects
.
create
(
...
...
@@ -129,7 +112,7 @@ class ProposalSerializer(serializers.ModelSerializer):
class
ProposalDetailSerializer
(
ProposalSerializer
):
""" Proposal serializer that includes votes """
votes
=
VoteSerializer
(
many
=
True
)
class
Meta
(
ProposalSerializer
.
Meta
):
fields
=
ProposalSerializer
.
Meta
.
fields
+
(
'votes'
,
...
...
@@ -152,13 +135,10 @@ class DossierSerializer(serializers.ModelSerializer):
class
DossierDetailSerializer
(
DossierSerializer
):
"""
Dossier serializer that includes proposals
and votes
"""
proposals
=
ProposalDetailSerializer
(
many
=
True
,
)
Dossier serializer that includes proposals and votes.
"""
proposals
=
ProposalDetailSerializer
(
many
=
True
)
class
Meta
(
DossierSerializer
.
Meta
):
fields
=
DossierSerializer
.
Meta
.
fields
+
(
...
...
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