Skip to content
Extraits de code Groupes Projets
Valider 2517fe20 rédigé par Nicolas Joyard's avatar Nicolas Joyard
Parcourir les fichiers

Add chamber creation helper

parent f2d3ba3e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -90,6 +90,18 @@ class GenericImporter(object): ...@@ -90,6 +90,18 @@ class GenericImporter(object):
return (instance, created) return (instance, created)
def ensure_chambers():
"""
Ensures chambers are created
"""
france = Country.objects.get(name="France")
for key in ('AN', 'SEN'):
variant = FranceDataVariants[key]
Chamber.objects.get_or_create(name=variant['chamber'],
abbreviation=variant['abbreviation'],
country=france)
class FranceDataImporter(GenericImporter): class FranceDataImporter(GenericImporter):
url = 'http://francedata.future/data/parlementaires.json' url = 'http://francedata.future/data/parlementaires.json'
...@@ -99,9 +111,7 @@ class FranceDataImporter(GenericImporter): ...@@ -99,9 +111,7 @@ class FranceDataImporter(GenericImporter):
def __init__(self, variant): def __init__(self, variant):
self.france = Country.objects.get(name="France") self.france = Country.objects.get(name="France")
self.variant = FranceDataVariants[variant] self.variant = FranceDataVariants[variant]
self.chamber, _ = Chamber.objects.get_or_create( self.chamber = Chamber.objects.get(name=self.variant['chamber'])
name=self.variant['chamber'],
abbreviation=self.variant['abbreviation'], country=self.france)
self.ch_constituency, _ = Constituency.objects.get_or_create( self.ch_constituency, _ = Constituency.objects.get_or_create(
name=self.variant['chamber'], country=self.france) name=self.variant['chamber'], country=self.france)
...@@ -311,6 +321,8 @@ def main(stream=None): ...@@ -311,6 +321,8 @@ def main(stream=None):
if not apps.ready: if not apps.ready:
django.setup() django.setup()
ensure_chambers()
an_importer = FranceDataImporter('AN') an_importer = FranceDataImporter('AN')
GenericImporter.pre_import(an_importer) GenericImporter.pre_import(an_importer)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter