Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
D
django-representatives
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
Validations
ac9cad63
Valider
ac9cad63
rédigé
11 years ago
par
Bram
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
[mod] refactor, put exporting functions in an utils.py
parent
480ae1eb
Branches
Branches contenant la validation
Étiquettes
É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/management/commands/export_in_representatives_format.py
+2
-44
2 ajouts, 44 suppressions
...s/management/commands/export_in_representatives_format.py
representatives/utils.py
+48
-0
48 ajouts, 0 suppression
representatives/utils.py
avec
50 ajouts
et
44 suppressions
representatives/management/commands/export_in_representatives_format.py
+
2
−
44
Voir le fichier @
ac9cad63
import
json
from
representatives.models
import
Representative
from
django.core.management.base
import
BaseCommand
from
representatives.utils
import
export_all_representatives
class
Command
(
BaseCommand
):
args
=
'
<poll_id poll_id ...>
'
help
=
'
Closes the specified poll for voting
'
def
handle
(
self
,
*
args
,
**
options
):
result
=
[]
personal_fields
=
(
"
first_name
"
,
"
last_name
"
,
"
full_name
"
,
"
birth_place
"
,
"
cv
"
)
gender_dict
=
dict
(
Representative
.
GENDER
)
for
representative
in
Representative
.
objects
.
all
():
reps
=
{
"
id
"
:
representative
.
remote_id
}
reps
[
"
personal
"
]
=
{
field
:
getattr
(
representative
,
field
)
for
field
in
personal_fields
}
reps
[
"
personal
"
][
"
gender
"
]
=
gender_dict
[
representative
.
gender
]
reps
[
"
personal
"
][
"
birth_date
"
]
=
representative
.
birth_date
.
strftime
(
"
%F
"
)
if
representative
.
birth_date
else
None
reps
[
"
contact
"
]
=
{}
reps
[
"
contact
"
][
"
emails
"
]
=
[{
"
email
"
:
email
.
email
,
"
type
"
:
email
.
kind
}
for
email
in
representative
.
email_set
.
all
()]
reps
[
"
contact
"
][
"
websites
"
]
=
[{
"
website
"
:
website
.
url
,
"
type
"
:
website
.
kind
}
for
website
in
representative
.
website_set
.
all
()]
reps
[
"
contact
"
][
"
phones
"
]
=
[{
"
phone
"
:
phone
.
number
,
"
type
"
:
phone
.
kind
,
"
address
"
:
phone
.
address_id
,
"
id
"
:
phone
.
id
}
for
phone
in
representative
.
phone_set
.
all
()]
reps
[
"
contact
"
][
"
address
"
]
=
[{
"
id
"
:
address
.
id
,
"
country
"
:
{
"
name
"
:
address
.
country
.
name
,
"
code
"
:
address
.
country
.
code
},
"
city
"
:
address
.
city
,
"
street
"
:
address
.
street
,
"
number
"
:
address
.
number
,
"
postcode
"
:
address
.
postcode
,
"
floor
"
:
address
.
floor
,
"
office_number
"
:
address
.
office_number
,
"
type
"
:
address
.
kind
,
"
geo
"
:
None
,
"
phones
"
:
[
phone
.
id
for
phone
in
address
.
phone_set
.
all
()],
}
for
address
in
representative
.
address_set
.
all
()]
reps
[
"
mandates
"
]
=
[{
"
name
"
:
mandate
.
name
,
"
type
"
:
mandate
.
kind
,
"
short_id
"
:
mandate
.
short_id
,
"
url_official
"
:
mandate
.
url
,
"
constituency
"
:
mandate
.
constituency
,
"
role
"
:
mandate
.
role
,
"
begin_date
"
:
mandate
.
begin_date
.
strftime
(
"
%F
"
)
if
mandate
.
begin_date
else
None
,
"
end_date
"
:
mandate
.
end_date
.
strftime
(
"
%F
"
)
if
mandate
.
end_date
else
None
,
"
current
"
:
mandate
.
active
,
}
for
mandate
in
representative
.
mandate_set
.
all
()]
result
.
append
(
reps
)
print
json
.
dumps
(
result
,
indent
=
4
)
print
json
.
dumps
(
export_all_representatives
(),
indent
=
4
)
Ce diff est replié.
Cliquez pour l'agrandir.
representatives/utils.py
0 → 100644
+
48
−
0
Voir le fichier @
ac9cad63
from
representatives.models
import
Representative
PERSONAL_FIELDS
=
(
"
first_name
"
,
"
last_name
"
,
"
full_name
"
,
"
birth_place
"
,
"
cv
"
)
GENDER_DICT
=
dict
(
Representative
.
GENDER
)
def
export_a_representative
(
representative
):
reps
=
{
"
id
"
:
representative
.
remote_id
}
reps
[
"
personal
"
]
=
{
field
:
getattr
(
representative
,
field
)
for
field
in
PERSONAL_FIELDS
}
reps
[
"
personal
"
][
"
gender
"
]
=
GENDER_DICT
[
representative
.
gender
]
reps
[
"
personal
"
][
"
birth_date
"
]
=
representative
.
birth_date
.
strftime
(
"
%F
"
)
if
representative
.
birth_date
else
None
reps
[
"
contact
"
]
=
{}
reps
[
"
contact
"
][
"
emails
"
]
=
[{
"
email
"
:
email
.
email
,
"
type
"
:
email
.
kind
}
for
email
in
representative
.
email_set
.
all
()]
reps
[
"
contact
"
][
"
websites
"
]
=
[{
"
website
"
:
website
.
url
,
"
type
"
:
website
.
kind
}
for
website
in
representative
.
website_set
.
all
()]
reps
[
"
contact
"
][
"
phones
"
]
=
[{
"
phone
"
:
phone
.
number
,
"
type
"
:
phone
.
kind
,
"
address
"
:
phone
.
address_id
,
"
id
"
:
phone
.
id
}
for
phone
in
representative
.
phone_set
.
all
()]
reps
[
"
contact
"
][
"
address
"
]
=
[{
"
id
"
:
address
.
id
,
"
country
"
:
{
"
name
"
:
address
.
country
.
name
,
"
code
"
:
address
.
country
.
code
},
"
city
"
:
address
.
city
,
"
street
"
:
address
.
street
,
"
number
"
:
address
.
number
,
"
postcode
"
:
address
.
postcode
,
"
floor
"
:
address
.
floor
,
"
office_number
"
:
address
.
office_number
,
"
type
"
:
address
.
kind
,
"
geo
"
:
None
,
"
phones
"
:
[
phone
.
id
for
phone
in
address
.
phone_set
.
all
()],
}
for
address
in
representative
.
address_set
.
all
()]
reps
[
"
mandates
"
]
=
[{
"
name
"
:
mandate
.
name
,
"
type
"
:
mandate
.
kind
,
"
short_id
"
:
mandate
.
short_id
,
"
url_official
"
:
mandate
.
url
,
"
constituency
"
:
mandate
.
constituency
,
"
role
"
:
mandate
.
role
,
"
begin_date
"
:
mandate
.
begin_date
.
strftime
(
"
%F
"
)
if
mandate
.
begin_date
else
None
,
"
end_date
"
:
mandate
.
end_date
.
strftime
(
"
%F
"
)
if
mandate
.
end_date
else
None
,
"
current
"
:
mandate
.
active
,
}
for
mandate
in
representative
.
mandate_set
.
all
()]
return
reps
def
export_all_representatives
():
return
[
export_a_representative
(
representative
)
for
representative
in
Representative
.
objects
.
all
()]
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