Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
D
django-representatives-votes
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de conteneurs
Registre de modèles
Opération
Environnements
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Ce projet est archivé. Le dépôt et les autres ressources du projet sont en lecture seule.
Afficher davantage de fils d'Ariane
La Quadrature du Net
Political Memory
django-representatives-votes
Validations
ae8a230a
Valider
ae8a230a
rédigé
9 years ago
par
James Pic
Parcourir les fichiers
Options
Téléchargements
Plain Diff
Merge pull request #12 from political-memory/api
API release
parents
eebec1ea
842da8b4
Branches
Branches contenant la validation
Étiquettes
0.0.8
Étiquettes contenant la validation
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
representatives_votes/api.py
+33
-10
33 ajouts, 10 suppressions
representatives_votes/api.py
representatives_votes/serializers.py
+10
-30
10 ajouts, 30 suppressions
representatives_votes/serializers.py
avec
43 ajouts
et
40 suppressions
representatives_votes/api.py
+
33
−
10
Voir le fichier @
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
'
],
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
representatives_votes/serializers.py
+
10
−
30
Voir le fichier @
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
+
(
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter