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
D
django-representatives
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Political Memory
django-representatives
Commits
9c1c97d1
Commit
9c1c97d1
authored
Feb 27, 2016
by
Nicolas Joyard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix francedata group abbreviations
parent
a2466349
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
252 additions
and
238 deletions
+252
-238
representatives/contrib/francedata/import_representatives.py
representatives/contrib/francedata/import_representatives.py
+2
-155
representatives/contrib/francedata/tests/representatives_expected.json
...es/contrib/francedata/tests/representatives_expected.json
+31
-83
representatives/contrib/francedata/variants.py
representatives/contrib/francedata/variants.py
+219
-0
No files found.
representatives/contrib/francedata/import_representatives.py
View file @
9c1c97d1
...
...
@@ -14,6 +14,8 @@ from django.utils import timezone
from
representatives.models
import
(
Country
,
Mandate
,
Email
,
Address
,
WebSite
,
Representative
,
Constituency
,
Phone
,
Group
,
Chamber
)
from
variants
import
FranceDataVariants
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -21,161 +23,6 @@ representative_pre_import = django.dispatch.Signal(
providing_args
=
[
'representative_data'
])
def
_get_rep_district_name
(
json
):
num
=
json
.
get
(
'num_circo'
)
nom
=
json
.
get
(
'nom_circo'
)
if
num
==
'nd'
:
return
nom
else
:
ordinal
=
u
'ère'
if
num
==
1
else
u
'ème'
return
'%s (%d%s circonscription)'
%
(
nom
,
num
,
ordinal
)
def
_get_rep_parl_groups
(
json
):
return
[{
'name'
:
g
[
'responsabilite'
][
'organisme'
],
'role'
:
g
[
'responsabilite'
][
'fonction'
],
'start'
:
json
[
'mandat_debut'
]
}
for
g
in
json
[
'groupes_parlementaires'
]]
def
_get_rep_comittees
(
json
):
return
[{
'name'
:
g
[
'responsabilite'
][
'organisme'
],
'role'
:
g
[
'responsabilite'
][
'fonction'
],
'start'
:
json
[
'mandat_debut'
]
}
for
g
in
json
[
'responsabilites'
]
if
g
[
'responsabilite'
][
'organisme'
].
startswith
(
'Commission'
)]
#
# Variant configuration
# - mail_domain is used to distinguish official vs personal emails
# - off_* fields are used for the official address of meps
# - mandates defines how mandates are created from the rep json
#
# Mandates are defined as follows
# - 'kind' indicates the group kind, a constant string
# - 'chamber' tells whether the group belongs to the chamber
# - 'from', if present, must be a function that takes the rep json and returns
# an array of dicts; one group will be created from each item in the dict.
# When 'from' is not present, only one group wil be created using the rep
# json (IOW, 'from' defaults to lambda repjson: [repjson])
# - 'name', 'abbr', 'role', 'start', 'end' are strings that are interpolated
# against the rep json or items returned by 'from'.
# - 'name_path', 'abbr_path', etc. can replace 'name', 'abbr'... by specifying
# a slash-separated dictionnary path where the value is to be found in the
# rep json or item returned by 'from'
# - 'name_fn', 'abbr_fn', etc. can also replace 'name', 'abbr'... by a
# function that takes the input item (rep json or item returned by 'from')
# and returns the value
#
FranceDataVariants
=
{
"AN"
:
{
"chamber"
:
u
"Assemblée nationale"
,
"remote_id_field"
:
"url_an"
,
"mail_domain"
:
"@assemblee-nationale.fr"
,
"off_city"
:
"Paris"
,
"off_street"
:
u
"Rue de l'Université"
,
"off_number"
:
"126"
,
"off_code"
:
"75355"
,
"off_name"
:
u
"Assemblée nationale"
,
"mandates"
:
[
{
"kind"
:
"group"
,
"chamber"
:
True
,
"abbr"
:
"%(groupe_sigle)s"
,
"name_path"
:
"groupe/organisme"
,
"role_path"
:
"groupe/fonction"
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"department"
,
"abbr"
:
"%(num_deptmt)s"
,
"name"
:
"%(nom_circo)s"
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"district"
,
"abbr"
:
"%(num_deptmt)s-%(num_circo)s"
,
"name_fn"
:
_get_rep_district_name
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"parl-group"
,
"chamber"
:
True
,
"from"
:
_get_rep_parl_groups
,
"abbr"
:
"%(name)s"
,
"name"
:
"%(name)s"
,
"role"
:
"%(role)s"
,
"start"
:
"%(start)s"
},
{
"kind"
:
"comittee"
,
"chamber"
:
True
,
"from"
:
_get_rep_comittees
,
"abbr"
:
"%(name)s"
,
"name"
:
"%(name)s"
,
"role"
:
"%(role)s"
,
"start"
:
"%(start)s"
}
]
},
"SEN"
:
{
"chamber"
:
u
"Sénat"
,
"remote_id_field"
:
"url_institution"
,
"mail_domain"
:
"@senat.fr"
,
"off_city"
:
"Paris"
,
"off_street"
:
u
"Rue de Vaugirard"
,
"off_number"
:
"15"
,
"off_code"
:
"75291"
,
"off_name"
:
u
"Palais du Luxembourg"
,
"mandates"
:
[
{
"kind"
:
"group"
,
"chamber"
:
True
,
"abbr"
:
"%(groupe_sigle)s"
,
"name_path"
:
"groupe/organisme"
,
"role_path"
:
"groupe/fonction"
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"department"
,
"abbr"
:
"%(num_deptmt)s"
,
"name"
:
"%(nom_circo)s"
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"district"
,
"abbr"
:
"%(num_deptmt)s-%(num_circo)s"
,
"name_fn"
:
_get_rep_district_name
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"parl-group"
,
"chamber"
:
True
,
"from"
:
_get_rep_parl_groups
,
"abbr"
:
"%(name)s"
,
"name"
:
"%(name)s"
,
"role"
:
"%(role)s"
,
"start"
:
"%(start)s"
},
{
"kind"
:
"comittee"
,
"chamber"
:
True
,
"from"
:
_get_rep_comittees
,
"abbr"
:
"%(name)s"
,
"name"
:
"%(name)s"
,
"role"
:
"%(role)s"
,
"start"
:
"%(start)s"
}
]
}
}
def
_get_mdef_item
(
mdef
,
item
,
json
,
default
=
None
):
if
item
in
mdef
:
return
mdef
[
item
]
%
json
...
...
representatives/contrib/francedata/tests/representatives_expected.json
View file @
9c1c97d1
...
...
@@ -134,6 +134,7 @@
"number"
:
"126"
,
"street"
:
"Rue de l'Universit
\u
00e9"
,
"representative"
:
1
,
"location"
:
""
,
"kind"
:
"official"
,
"postcode"
:
"75355"
},
...
...
@@ -148,6 +149,7 @@
"number"
:
"20"
,
"street"
:
"Rue d'Arras"
,
"representative"
:
1
,
"location"
:
""
,
"kind"
:
""
,
"postcode"
:
"59000"
},
...
...
@@ -162,6 +164,7 @@
"number"
:
""
,
"street"
:
""
,
"representative"
:
1
,
"location"
:
""
,
"kind"
:
""
,
"postcode"
:
"59000"
},
...
...
@@ -176,6 +179,7 @@
"number"
:
"15"
,
"street"
:
"Rue de Vaugirard"
,
"representative"
:
2
,
"location"
:
""
,
"kind"
:
"official"
,
"postcode"
:
"75291"
},
...
...
@@ -268,35 +272,15 @@
"model"
:
"representatives.group"
,
"pk"
:
6
},
{
"fields"
:
{
"name"
:
"Groupe d'amiti
\u
00e9 france-mexique"
,
"kind"
:
"parl-group"
,
"abbreviation"
:
"Groupe d'amiti
\u
00e9 france-mexique"
,
"chamber"
:
1
},
"model"
:
"representatives.group"
,
"pk"
:
7
},
{
"fields"
:
{
"name"
:
"Groupe d'amiti
\u
00e9 france-argentine"
,
"kind"
:
"parl-group"
,
"abbreviation"
:
"Groupe d'amiti
\u
00e9 france-argentine"
,
"chamber"
:
1
},
"model"
:
"representatives.group"
,
"pk"
:
8
},
{
"fields"
:
{
"name"
:
"Commission des lois constitutionnelles, de la l
\u
00e9gislation et de l'administration g
\u
00e9n
\u
00e9rale de la r
\u
00e9publique"
,
"kind"
:
"comittee"
,
"abbreviation"
:
"
Commission des lois constitutionnelles, de la l
\u
00e9gislation et de l'administration g
\u
00e9n
\u
00e9rale de la r
\u
00e9publique
"
,
"abbreviation"
:
"
AnComLois
"
,
"chamber"
:
1
},
"model"
:
"representatives.group"
,
"pk"
:
9
"pk"
:
7
},
{
"fields"
:
{
...
...
@@ -306,7 +290,7 @@
"chamber"
:
2
},
"model"
:
"representatives.group"
,
"pk"
:
10
"pk"
:
8
},
{
"fields"
:
{
...
...
@@ -316,7 +300,7 @@
"chamber"
:
null
},
"model"
:
"representatives.group"
,
"pk"
:
11
"pk"
:
9
},
{
"fields"
:
{
...
...
@@ -326,27 +310,17 @@
"chamber"
:
null
},
"model"
:
"representatives.group"
,
"pk"
:
12
},
{
"fields"
:
{
"name"
:
"Groupe France-Japon"
,
"kind"
:
"parl-group"
,
"abbreviation"
:
"Groupe France-Japon"
,
"chamber"
:
2
},
"model"
:
"representatives.group"
,
"pk"
:
13
"pk"
:
10
},
{
"fields"
:
{
"name"
:
"Commission de la culture, de l'
\u
00e9ducation et de la communication"
,
"kind"
:
"comittee"
,
"abbreviation"
:
"
Commission de la culture, de l'
\u
00e9ducation et de la communication
"
,
"abbreviation"
:
"
SenComCult
"
,
"chamber"
:
2
},
"model"
:
"representatives.group"
,
"pk"
:
1
4
"pk"
:
1
1
},
{
"fields"
:
{
...
...
@@ -378,6 +352,7 @@
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
1
,
"link"
:
""
,
"begin_date"
:
null
,
"constituency"
:
3
},
...
...
@@ -390,6 +365,7 @@
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
1
,
"link"
:
""
,
"begin_date"
:
"2012-06-20"
,
"constituency"
:
1
},
...
...
@@ -402,6 +378,7 @@
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
1
,
"link"
:
""
,
"begin_date"
:
"2012-06-20"
,
"constituency"
:
1
},
...
...
@@ -414,6 +391,7 @@
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
1
,
"link"
:
""
,
"begin_date"
:
"2012-06-20"
,
"constituency"
:
1
},
...
...
@@ -424,37 +402,14 @@
"fields"
:
{
"group"
:
7
,
"end_date"
:
null
,
"role"
:
"vice-pr
\u
00e9sident"
,
"representative"
:
1
,
"begin_date"
:
"2012-06-20"
,
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
5
},
{
"fields"
:
{
"group"
:
8
,
"end_date"
:
null
,
"role"
:
"vice-pr
\u
00e9sident"
,
"representative"
:
1
,
"begin_date"
:
"2012-06-20"
,
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
6
},
{
"fields"
:
{
"group"
:
9
,
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
1
,
"link"
:
""
,
"begin_date"
:
"2012-06-20"
,
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
7
"pk"
:
5
},
{
"fields"
:
{
...
...
@@ -462,70 +417,63 @@
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
2
,
"link"
:
""
,
"begin_date"
:
null
,
"constituency"
:
3
},
"model"
:
"representatives.mandate"
,
"pk"
:
8
"pk"
:
6
},
{
"fields"
:
{
"group"
:
10
,
"group"
:
8
,
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
2
,
"link"
:
""
,
"begin_date"
:
"2004-09-26"
,
"constituency"
:
2
},
"model"
:
"representatives.mandate"
,
"pk"
:
9
"pk"
:
7
},
{
"fields"
:
{
"group"
:
11
,
"group"
:
9
,
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
2
,
"link"
:
""
,
"begin_date"
:
"2004-09-26"
,
"constituency"
:
2
},
"model"
:
"representatives.mandate"
,
"pk"
:
10
"pk"
:
8
},
{
"fields"
:
{
"group"
:
1
2
,
"group"
:
1
0
,
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
2
,
"link"
:
""
,
"begin_date"
:
"2004-09-26"
,
"constituency"
:
2
},
"model"
:
"representatives.mandate"
,
"pk"
:
11
},
{
"fields"
:
{
"group"
:
13
,
"end_date"
:
null
,
"role"
:
"pr
\u
00e9sident"
,
"representative"
:
2
,
"begin_date"
:
"2004-09-26"
,
"constituency"
:
2
},
"model"
:
"representatives.mandate"
,
"pk"
:
12
"pk"
:
9
},
{
"fields"
:
{
"group"
:
1
4
,
"group"
:
1
1
,
"end_date"
:
null
,
"role"
:
"vice-pr
\u
00e9sident"
,
"representative"
:
2
,
"link"
:
""
,
"begin_date"
:
"2004-09-26"
,
"constituency"
:
2
},
"model"
:
"representatives.mandate"
,
"pk"
:
1
3
"pk"
:
1
0
}
]
representatives/contrib/francedata/variants.py
0 → 100644
View file @
9c1c97d1
# coding: utf-8
# Equivalences of nat. Assembly committees
_equiv_Com_AN
=
{
}
# Abbreviations for nat. Assembly committees
_abbr_Com_AN
=
{
(
u
"Commission chargée de l'application de l'article 26 de la "
u
"constitution"
):
"AnComImmu"
,
u
"Commission de la défense nationale et des forces armées"
:
"AnComDef"
,
u
"Commission des affaires culturelles et de l'éducation"
:
"AnComCult"
,
u
"Commission des affaires économiques"
:
"AnComEco"
,
u
"Commission des affaires étrangères"
:
"AnComEtrg"
,
u
"Commission des affaires européennes"
:
"AnComEU"
,
u
"Commission des affaires sociales"
:
"AnComSoc"
,
(
u
"Commission des finances, de l'économie générale et du contrôle "
u
"budgétaire"
):
"AnComFin"
,
(
u
"Commission des lois constitutionnelles, de la législation et de "
u
"l'administration générale de la république"
):
"AnComLois"
,
u
"Commission du développement durable et de l'aménagement du territoire"
:
"AnComDevD"
}
# Equivalences of Senate committees
_equiv_Com_SEN
=
{
u
"COMMISSION DES AFFAIRES EUROPÉENNES Commission des affaires européennes"
:
u
"Commission des affaires européennes"
,
u
"Commission de l'aménagement du territoire et du développement durable"
:
(
u
"Commission du développement durable, des infrastructures, de "
u
"l'équipement et de l'aménagement du territoire"
)
}
# Abbreviations for Senate committees
_abbr_Com_SEN
=
{
u
"Commission de la culture, de l'éducation et de la communication"
:
"SenComCult"
,
u
"Commission des affaires économiques"
:
"SenComEco"
,
u
"Commission des affaires étrangères, de la défense et des forces armées"
:
"SenComDef"
,
u
"Commission des affaires européennes"
:
"SenComEU"
,
u
"Commission des affaires sociales"
:
"SenComSoc"
,
(
u
"Commission des finances, du contrôle budgétaire et des comptes "
u
"économiques de la nation"
):
"SenComFin"
,
(
u
"Commission des lois constitutionnelles, de législation, du suffrage "
u
"universel, du Règlement et d'administration générale"
):
"SenComLois"
,
(
u
"Commission du développement durable, des infrastructures, de "
u
"l'équipement et de l'aménagement du territoire"
):
"SenComDevD"
,
u
"Commission sénatoriale pour le contrôle de l'application des lois"
:
"SenComAppL"
}
def
_get_rep_district_name
(
json
):
num
=
json
.
get
(
'num_circo'
)
nom
=
json
.
get
(
'nom_circo'
)
if
num
==
'nd'
:
return
nom
else
:
ordinal
=
u
'ère'
if
num
==
1
else
u
'ème'
return
'%s (%d%s circonscription)'
%
(
nom
,
num
,
ordinal
)
def
_get_sen_comittees
(
json
):
comittees
=
[]
start
=
json
[
'mandat_debut'
]
for
g
in
json
[
'responsabilites'
]:
orga
=
g
[
'responsabilite'
][
'organisme'
]
role
=
g
[
'responsabilite'
][
'fonction'
]
if
not
orga
.
startswith
(
'Commission'
):
continue
if
orga
in
_equiv_Com_SEN
:
orga
=
_equiv_Com_SEN
[
orga
]
comittees
.
append
({
'abbr'
:
_abbr_Com_SEN
[
orga
]
if
orga
in
_abbr_Com_SEN
else
''
,
'name'
:
orga
,
'role'
:
role
,
'start'
:
start
})
return
comittees
def
_get_an_comittees
(
json
):
comittees
=
[]
start
=
json
[
'mandat_debut'
]
for
g
in
json
[
'responsabilites'
]:
orga
=
g
[
'responsabilite'
][
'organisme'
]
role
=
g
[
'responsabilite'
][
'fonction'
]
if
not
orga
.
startswith
(
'Commission'
):
continue
if
orga
in
_equiv_Com_AN
:
orga
=
_equiv_Com_AN
[
orga
]
comittees
.
append
({
'abbr'
:
_abbr_Com_AN
[
orga
]
if
orga
in
_abbr_Com_AN
else
''
,
'name'
:
orga
,
'role'
:
role
,
'start'
:
start
})
return
comittees
#
# Variant configuration
# - mail_domain is used to distinguish official vs personal emails
# - off_* fields are used for the official address of meps
# - mandates defines how mandates are created from the rep json
#
# Mandates are defined as follows
# - 'kind' indicates the group kind, a constant string
# - 'chamber' tells whether the group belongs to the chamber
# - 'from', if present, must be a function that takes the rep json and returns
# an array of dicts; one group will be created from each item in the dict.
# When 'from' is not present, only one group wil be created using the rep
# json (IOW, 'from' defaults to lambda repjson: [repjson])
# - 'name', 'abbr', 'role', 'start', 'end' are strings that are interpolated
# against the rep json or items returned by 'from'.
# - 'name_path', 'abbr_path', etc. can replace 'name', 'abbr'... by specifying
# a slash-separated dictionnary path where the value is to be found in the
# rep json or item returned by 'from'
# - 'name_fn', 'abbr_fn', etc. can also replace 'name', 'abbr'... by a
# function that takes the input item (rep json or item returned by 'from')
# and returns the value
#
FranceDataVariants
=
{
"AN"
:
{
"chamber"
:
u
"Assemblée nationale"
,
"remote_id_field"
:
"url_an"
,
"mail_domain"
:
"@assemblee-nationale.fr"
,
"off_city"
:
"Paris"
,
"off_street"
:
u
"Rue de l'Université"
,
"off_number"
:
"126"
,
"off_code"
:
"75355"
,
"off_name"
:
u
"Assemblée nationale"
,
"mandates"
:
[
{
"kind"
:
"group"
,
"chamber"
:
True
,
"abbr"
:
"%(groupe_sigle)s"
,
"name_path"
:
"groupe/organisme"
,
"role_path"
:
"groupe/fonction"
,
"start"
:
"%(mandat_debut)s"
},
{
"kind"
:
"department"
,
"abbr"
:
"%(num_deptmt)s"
,
"name"
:
"%(nom_circo)s"
,
"start"
:
"%(mandat_debut)s"
},
{