Commit dcb7caee authored by James Pic's avatar James Pic

Merge pull request #21 from njoyard/master

#MemopolMiniHackaton fixes
parents 122f28aa b25e866d
......@@ -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):
......
......@@ -131,8 +131,10 @@
"city": "Paris",
"name": "Assembl\u00e9e nationale",
"country": 1095,
"floor": "",
"number": "126",
"street": "Rue de l'Universit\u00e9",
"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\u00e9e nationale"
"name": "Assembl\u00e9e nationale",
"abbreviation": "AN"
},
"model": "representatives.chamber",
"pk": 1
......@@ -207,41 +216,32 @@
{
"fields": {
"country": 1095,
"name": "S\u00e9nat"
"name": "S\u00e9nat",
"abbreviation": "SEN"
},
"model": "representatives.chamber",
"pk": 2
},
{
"fields": {
"name": "Assembl\u00e9e nationale",
"kind": "chamber",
"abbreviation": "AN",
"chamber": 1
"name": "France",
"kind": "country",
"abbreviation": "FR",
"chamber": null
},
"model": "representatives.group",
"pk": 1
},
{
"fields": {
"name": "S\u00e9nat",
"name": "Assembl\u00e9e nationale",
"kind": "chamber",
"abbreviation": "SEN",
"chamber": 2
"abbreviation": "AN",
"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\u00e9publicain 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\u00e9gislation et de l'administration g\u00e9n\u00e9rale de la r\u00e9publique",
"kind": "comittee",
"kind": "committee",
"abbreviation": "AnComLois",
"chamber": 1
},
"model": "representatives.group",
"pk": 6
},
{
"fields": {
"name": "Bureau de l'assembl\u00e9e nationale",
"kind": "delegation",
"abbreviation": "",
"chamber": 1
},
"model": "representatives.group",
"pk": 7
},
{
"fields": {
"name": "D\u00e9l\u00e9gation charg\u00e9e de la communication et de la presse",
"kind": "delegation",
"abbreviation": "",
"chamber": 1
},
"model": "representatives.group",
"pk": 8
},
{
"fields": {
"name": "Groupe d'amiti\u00e9 france-mexique",
"kind": "delegation",
"abbreviation": "",
"chamber": 1
},
"model": "representatives.group",
"pk": 9
},
{
"fields": {
"name": "Groupe d'amiti\u00e9 france-argentine",
"kind": "delegation",
"abbreviation": "",
"chamber": 1
},
"model": "representatives.group",
"pk": 10
},
{
"fields": {
"name": "S\u00e9nat",
"kind": "chamber",
"abbreviation": "SEN",
"chamber": 2
},
"model": "representatives.group",
"pk": 11
},
{
"fields": {
"name": "Socialiste et r\u00e9publicain",
......@@ -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": 10
"pk": 14
},
{
"fields": {
"name": "Commission de la culture, de l'\u00e9ducation et de la communication",
"kind": "comittee",
"kind": "committee",
"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\u00e9put\u00e9",
"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\u00e9sident",
"representative": 1,
"link": "",
"begin_date": "2012-06-20",
"constituency": 1
},
"model": "representatives.mandate",
"pk": 9
},
{
"fields": {
"group": 10,
"end_date": null,
"role": "vice-pr\u00e9sident",
"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\u00e9nateur",
"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": 10,
"group": 14,
"end_date": null,
"role": "membre",
"representative": 2,
......@@ -461,11 +599,11 @@
"constituency": 2
},
"model": "representatives.mandate",
"pk": 9
"pk": 15
},
{
"fields": {
"group": 11,
"group": 15,
"end_date": null,
"role": "vice-pr\u00e9sident",
"representative": 2,
......@@ -474,6 +612,19 @@
"constituency": 2
},
"model": "representatives.mandate",
"pk": 10
"pk": 16
},
{
"fields": {
"group": 16,
"end_date": null,
"role": "pr\u00e9sident",
"representative": 2,
"link": "",
"begin_date": "2004-09-26",
"constituency": 2
},
"model": "representatives.mandate",
"pk": 17
}
]
# 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,