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
dcb7caee
Commit
dcb7caee
authored
Apr 19, 2016
by
James Pic
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21 from njoyard/master
#MemopolMiniHackaton fixes
parents
122f28aa
b25e866d
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
391 additions
and
155 deletions
+391
-155
representatives/contrib/francedata/import_representatives.py
representatives/contrib/francedata/import_representatives.py
+2
-4
representatives/contrib/francedata/tests/representatives_expected.json
...es/contrib/francedata/tests/representatives_expected.json
+194
-43
representatives/contrib/francedata/variants.py
representatives/contrib/francedata/variants.py
+112
-87
representatives/contrib/parltrack/import_representatives.py
representatives/contrib/parltrack/import_representatives.py
+1
-1
representatives/contrib/parltrack/tests/representatives_expected.json
...ves/contrib/parltrack/tests/representatives_expected.json
+2
-1
representatives/migrations/0015_chamber_abbreviation.py
representatives/migrations/0015_chamber_abbreviation.py
+19
-0
representatives/models.py
representatives/models.py
+13
-3
representatives/templatetags/representatives_tags.py
representatives/templatetags/representatives_tags.py
+10
-1
representatives/tests/response_fixtures/RepresentativeManagerTest.test_constituencies_api/status_code
...esentativeManagerTest.test_constituencies_api/status_code
+1
-0
representatives/tests/response_fixtures/RepresentativeManagerTest.test_groups_api/status_code
...res/RepresentativeManagerTest.test_groups_api/status_code
+1
-0
representatives/tests/response_fixtures/RepresentativeManagerTest.test_mandates_api/status_code
...s/RepresentativeManagerTest.test_mandates_api/status_code
+1
-0
representatives/tests/response_fixtures/RepresentativeManagerTest.test_representatives_api/status_code
...sentativeManagerTest.test_representatives_api/status_code
+1
-0
representatives/urls.py
representatives/urls.py
+6
-1
representatives/views.py
representatives/views.py
+28
-14
No files found.
representatives/contrib/francedata/import_representatives.py
View file @
dcb7caee
...
...
@@ -97,12 +97,10 @@ class FranceDataImporter(GenericImporter):
self
.
france
=
Country
.
objects
.
get
(
name
=
"France"
)
self
.
variant
=
FranceDataVariants
[
variant
]
self
.
chamber
,
_
=
Chamber
.
objects
.
get_or_create
(
name
=
self
.
variant
[
'chamber'
],
country
=
self
.
france
)
name
=
self
.
variant
[
'chamber'
],
abbreviation
=
self
.
variant
[
'abbreviation'
],
country
=
self
.
france
)
self
.
ch_constituency
,
_
=
Constituency
.
objects
.
get_or_create
(
name
=
self
.
variant
[
'chamber'
],
country
=
self
.
france
)
self
.
ch_group
,
_
=
Group
.
objects
.
get_or_create
(
name
=
self
.
variant
[
'chamber'
],
kind
=
'chamber'
,
abbreviation
=
variant
,
chamber
=
self
.
chamber
)
@
transaction
.
atomic
def
manage_rep
(
self
,
rep_json
):
...
...
representatives/contrib/francedata/tests/representatives_expected.json
View file @
dcb7caee
...
...
@@ -131,8 +131,10 @@
"city"
:
"Paris"
,
"name"
:
"Assembl
\u
00e9e nationale"
,
"country"
:
1095
,
"floor"
:
""
,
"number"
:
"126"
,
"street"
:
"Rue de l'Universit
\u
00e9"
,
"office_number"
:
""
,
"representative"
:
1
,
"location"
:
""
,
"kind"
:
"official"
,
...
...
@@ -146,8 +148,10 @@
"city"
:
"Lille"
,
"name"
:
"Permanence"
,
"country"
:
1095
,
"floor"
:
""
,
"number"
:
"20"
,
"street"
:
"Rue d'Arras"
,
"office_number"
:
""
,
"representative"
:
1
,
"location"
:
""
,
"kind"
:
""
,
...
...
@@ -161,8 +165,10 @@
"city"
:
"Lille"
,
"name"
:
""
,
"country"
:
1095
,
"floor"
:
""
,
"number"
:
""
,
"street"
:
""
,
"office_number"
:
""
,
"representative"
:
1
,
"location"
:
""
,
"kind"
:
""
,
...
...
@@ -176,8 +182,10 @@
"city"
:
"Paris"
,
"name"
:
"Palais du Luxembourg"
,
"country"
:
1095
,
"floor"
:
""
,
"number"
:
"15"
,
"street"
:
"Rue de Vaugirard"
,
"office_number"
:
""
,
"representative"
:
2
,
"location"
:
""
,
"kind"
:
"official"
,
...
...
@@ -199,7 +207,8 @@
{
"fields"
:
{
"country"
:
1095
,
"name"
:
"Assembl
\u
00e9e nationale"
"name"
:
"Assembl
\u
00e9e nationale"
,
"abbreviation"
:
"AN"
},
"model"
:
"representatives.chamber"
,
"pk"
:
1
...
...
@@ -207,41 +216,32 @@
{
"fields"
:
{
"country"
:
1095
,
"name"
:
"S
\u
00e9nat"
"name"
:
"S
\u
00e9nat"
,
"abbreviation"
:
"SEN"
},
"model"
:
"representatives.chamber"
,
"pk"
:
2
},
{
"fields"
:
{
"name"
:
"
Assembl
\u
00e9e national
e"
,
"kind"
:
"c
hamber
"
,
"abbreviation"
:
"
AN
"
,
"chamber"
:
1
"name"
:
"
Franc
e"
,
"kind"
:
"c
ountry
"
,
"abbreviation"
:
"
FR
"
,
"chamber"
:
null
},
"model"
:
"representatives.group"
,
"pk"
:
1
},
{
"fields"
:
{
"name"
:
"
S
\u
00e9nat
"
,
"name"
:
"
Assembl
\u
00e9e nationale
"
,
"kind"
:
"chamber"
,
"abbreviation"
:
"
SE
N"
,
"chamber"
:
2
"abbreviation"
:
"
A
N"
,
"chamber"
:
1
},
"model"
:
"representatives.group"
,
"pk"
:
2
},
{
"fields"
:
{
"name"
:
"France"
,
"kind"
:
"country"
,
"abbreviation"
:
"FR"
,
"chamber"
:
null
},
"model"
:
"representatives.group"
,
"pk"
:
3
},
{
"fields"
:
{
"name"
:
"Socialiste, r
\u
00e9publicain et citoyen"
,
...
...
@@ -250,7 +250,7 @@
"chamber"
:
1
},
"model"
:
"representatives.group"
,
"pk"
:
4
"pk"
:
3
},
{
"fields"
:
{
...
...
@@ -260,7 +260,7 @@
"chamber"
:
null
},
"model"
:
"representatives.group"
,
"pk"
:
5
"pk"
:
4
},
{
"fields"
:
{
...
...
@@ -270,18 +270,68 @@
"chamber"
:
null
},
"model"
:
"representatives.group"
,
"pk"
:
6
"pk"
:
5
},
{
"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"
,
"kind"
:
"com
m
ittee"
,
"abbreviation"
:
"AnComLois"
,
"chamber"
:
1
},
"model"
:
"representatives.group"
,
"pk"
:
6
},
{
"fields"
:
{
"name"
:
"Bureau de l'assembl
\u
00e9e nationale"
,
"kind"
:
"delegation"
,
"abbreviation"
:
""
,
"chamber"
:
1
},
"model"
:
"representatives.group"
,
"pk"
:
7
},
{
"fields"
:
{
"name"
:
"D
\u
00e9l
\u
00e9gation charg
\u
00e9e de la communication et de la presse"
,
"kind"
:
"delegation"
,
"abbreviation"
:
""
,
"chamber"
:
1
},
"model"
:
"representatives.group"
,
"pk"
:
8
},
{
"fields"
:
{
"name"
:
"Groupe d'amiti
\u
00e9 france-mexique"
,
"kind"
:
"delegation"
,
"abbreviation"
:
""
,
"chamber"
:
1
},
"model"
:
"representatives.group"
,
"pk"
:
9
},
{
"fields"
:
{
"name"
:
"Groupe d'amiti
\u
00e9 france-argentine"
,
"kind"
:
"delegation"
,
"abbreviation"
:
""
,
"chamber"
:
1
},
"model"
:
"representatives.group"
,
"pk"
:
10
},
{
"fields"
:
{
"name"
:
"S
\u
00e9nat"
,
"kind"
:
"chamber"
,
"abbreviation"
:
"SEN"
,
"chamber"
:
2
},
"model"
:
"representatives.group"
,
"pk"
:
11
},
{
"fields"
:
{
"name"
:
"Socialiste et r
\u
00e9publicain"
,
...
...
@@ -290,7 +340,7 @@
"chamber"
:
2
},
"model"
:
"representatives.group"
,
"pk"
:
8
"pk"
:
12
},
{
"fields"
:
{
...
...
@@ -300,7 +350,7 @@
"chamber"
:
null
},
"model"
:
"representatives.group"
,
"pk"
:
9
"pk"
:
13
},
{
"fields"
:
{
...
...
@@ -310,17 +360,27 @@
"chamber"
:
null
},
"model"
:
"representatives.group"
,
"pk"
:
1
0
"pk"
:
1
4
},
{
"fields"
:
{
"name"
:
"Commission de la culture, de l'
\u
00e9ducation et de la communication"
,
"kind"
:
"comittee"
,
"kind"
:
"com
m
ittee"
,
"abbreviation"
:
"SenComCult"
,
"chamber"
:
2
},
"model"
:
"representatives.group"
,
"pk"
:
11
"pk"
:
15
},
{
"fields"
:
{
"name"
:
"Groupe France-Japon"
,
"kind"
:
"delegation"
,
"abbreviation"
:
""
,
"chamber"
:
2
},
"model"
:
"representatives.group"
,
"pk"
:
16
},
{
"fields"
:
{
...
...
@@ -348,7 +408,7 @@
},
{
"fields"
:
{
"group"
:
3
,
"group"
:
1
,
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
1
,
...
...
@@ -359,6 +419,32 @@
"model"
:
"representatives.mandate"
,
"pk"
:
1
},
{
"fields"
:
{
"group"
:
2
,
"end_date"
:
null
,
"role"
:
"D
\u
00e9put
\u
00e9"
,
"representative"
:
1
,
"link"
:
""
,
"begin_date"
:
"2012-06-20"
,
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
2
},
{
"fields"
:
{
"group"
:
3
,
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
1
,
"link"
:
""
,
"begin_date"
:
"2012-06-20"
,
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
3
},
{
"fields"
:
{
"group"
:
4
,
...
...
@@ -370,7 +456,7 @@
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
2
"pk"
:
4
},
{
"fields"
:
{
...
...
@@ -383,7 +469,7 @@
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
3
"pk"
:
5
},
{
"fields"
:
{
...
...
@@ -396,12 +482,25 @@
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
4
"pk"
:
6
},
{
"fields"
:
{
"group"
:
7
,
"end_date"
:
null
,
"role"
:
"questeur"
,
"representative"
:
1
,
"link"
:
""
,
"begin_date"
:
"2012-06-20"
,
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
7
},
{
"fields"
:
{
"group"
:
8
,
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
1
,
"link"
:
""
,
...
...
@@ -409,11 +508,37 @@
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
5
"pk"
:
8
},
{
"fields"
:
{
"group"
:
3
,
"group"
:
9
,
"end_date"
:
null
,
"role"
:
"vice-pr
\u
00e9sident"
,
"representative"
:
1
,
"link"
:
""
,
"begin_date"
:
"2012-06-20"
,
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
9
},
{
"fields"
:
{
"group"
:
10
,
"end_date"
:
null
,
"role"
:
"vice-pr
\u
00e9sident"
,
"representative"
:
1
,
"link"
:
""
,
"begin_date"
:
"2012-06-20"
,
"constituency"
:
1
},
"model"
:
"representatives.mandate"
,
"pk"
:
10
},
{
"fields"
:
{
"group"
:
1
,
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
2
,
...
...
@@ -422,11 +547,24 @@
"constituency"
:
3
},
"model"
:
"representatives.mandate"
,
"pk"
:
6
"pk"
:
11
},
{
"fields"
:
{
"group"
:
8
,
"group"
:
11
,
"end_date"
:
null
,
"role"
:
"S
\u
00e9nateur"
,
"representative"
:
2
,
"link"
:
""
,
"begin_date"
:
"2004-09-26"
,
"constituency"
:
2
},
"model"
:
"representatives.mandate"
,
"pk"
:
12
},
{
"fields"
:
{
"group"
:
12
,
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
2
,
...
...
@@ -435,11 +573,11 @@
"constituency"
:
2
},
"model"
:
"representatives.mandate"
,
"pk"
:
7
"pk"
:
13
},
{
"fields"
:
{
"group"
:
9
,
"group"
:
13
,
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
2
,
...
...
@@ -448,11 +586,11 @@
"constituency"
:
2
},
"model"
:
"representatives.mandate"
,
"pk"
:
8
"pk"
:
14
},
{
"fields"
:
{
"group"
:
1
0
,
"group"
:
1
4
,
"end_date"
:
null
,
"role"
:
"membre"
,
"representative"
:
2
,
...
...
@@ -461,11 +599,11 @@
"constituency"
:
2
},
"model"
:
"representatives.mandate"
,
"pk"
:
9
"pk"
:
15
},
{
"fields"
:
{
"group"
:
1
1
,
"group"
:
1
5
,
"end_date"
:
null
,
"role"
:
"vice-pr
\u
00e9sident"
,
"representative"
:
2
,
...
...
@@ -474,6 +612,19 @@
"constituency"
:
2
},
"model"
:
"representatives.mandate"
,
"pk"
:
10
"pk"
:
16
},
{
"fields"
:
{
"group"
:
16
,
"end_date"
:
null
,
"role"
:
"pr
\u
00e9sident"
,
"representative"
:
2
,
"link"
:
""
,
"begin_date"
:
"2004-09-26"
,
"constituency"
:
2
},
"model"
:
"representatives.mandate"
,
"pk"
:
17
}
]
representatives/contrib/francedata/variants.py
View file @
dcb7caee
# 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"
}
class
DelegationHelper
:
'''
Helper class for building committees/delegations from rep json data
given dicts for equivalences and abbreviations
'''
def
__init__
(
self
,
equivs
,
abbrevs
,
committees
=
True
):
self
.
equivs
=
equivs
self
.
abbrevs
=
abbrevs
self
.
committees
=
committees
def
__call__
(
self
,
data
):
items
=
[]
start
=
data
[
'mandat_debut'
]
if
self
.
committees
:
gdata
=
(
i
[
'responsabilite'
]
for
i
in
data
[
'responsabilites'
])
else
:
gdata
=
([
i
[
'responsabilite'
]
for
i
in
data
[
'responsabilites'
]]
+
[
j
[
'responsabilite'
]
for
j
in
data
[
'groupes_parlementaires'
]])
for
g
in
gdata
:
orga
=
g
[
'organisme'
]
role
=
g
[
'fonction'
]
if
self
.
committees
!=
orga
.
lower
().
startswith
(
'commission'
):
continue
if
orga
in
self
.
equivs
:
orga
=
self
.
equivs
[
orga
]
items
.
append
({
'abbr'
:
self
.
abbrevs
[
orga
]
if
orga
in
self
.
abbrevs
else
''
,
'name'
:
orga
,
'role'
:
role
,
'start'
:
start
})
# Equivalences of Senate committees
_equiv_Com_SEN
=
{
return
items
def
_get_rep_district_name
(
data
):
num
=
data
.
get
(
'num_circo'
)
nom
=
data
.
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
)
_get_sen_committees
=
DelegationHelper
({
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"
,
...
...
@@ -48,66 +75,28 @@ _abbr_Com_SEN = {
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
,