Commit 2f6b2a7f by Nicolas Joyard

Ajout last modified job scrutins

parent 12c9f963
Showing with 31 additions and 33 deletions
......@@ -31,39 +31,36 @@ class ImportScrutinsJob(BaseANJob):
def save_scrutin(self, json):
self.current = u'Scrutin %s' % json['uid']
scrutin, _ = self.get_or_create(Scrutin, id=json['uid'])
scrutin.numero = int(json['numero'])
scrutin.date = self.parse_date(json['dateScrutin'])
scrutin.quantieme_jour_seance = int(json['quantiemeJourSeance'])
scrutin.titre = json['titre']
scrutin.demandeur = json['demandeur']['texte']
scrutin.objet = json['objet']['libelle']
scrutin.type_code = json['typeVote']['codeTypeVote']
scrutin.type_libelle = json['typeVote']['libelleTypeVote']
scrutin.type_majorite = json['typeVote']['typeMajorite']
scrutin.sort_code = json['sort']['code']
scrutin.sort_libelle = json['sort']['libelle']
scrutin.mode_publication = json['modePublicationDesVotes']
sy = json['syntheseVote']
scrutin.synthese_votants = int(sy['nombreVotants'])
scrutin.synthese_exprimes = int(sy['suffragesExprimes'])
scrutin.synthese_requis = int(sy['nbrSuffragesRequis'])
scrutin.synthese_pour = int(sy['decompte']['pour'])
scrutin.synthese_contre = int(sy['decompte']['contre'])
scrutin.synthese_abstention = int(sy['decompte']['abstention'])
scrutin.synthese_nonvotant = int(sy['decompte']['nonVotant'])
scrutin.legislature = self.get_cached(Legislature,
int(json['legislature']))
scrutin.organe = self.get_cached(Organe, json['organeRef'])
gr = json['ventilationVotes']['organe']['groupes']['groupe']
scrutin.groupes = [self.save_groupe(g) for g in gr]
data = {
'date': self.parse_date(json['dateScrutin']),
'demandeur': json['demandeur']['texte'],
'groupes': [self.save_groupe(g) for g in gr],
'legislature': self.save(Legislature, int(json['legislature'])),
'mode_publication': json['modePublicationDesVotes'],
'numero': int(json['numero']),
'objet': json['objet']['libelle'],
'organe': self.save(Organe, json['organeRef']),
'quantieme_jour_seance': int(json['quantiemeJourSeance']),
'sort_code': json['sort']['code'],
'sort_libelle': json['sort']['libelle'],
'synthese_abstention': int(sy['decompte']['abstention']),
'synthese_contre': int(sy['decompte']['contre']),
'synthese_exprimes': int(sy['suffragesExprimes']),
'synthese_nonvotant': int(sy['decompte']['nonVotant']),
'synthese_pour': int(sy['decompte']['pour']),
'synthese_requis': int(sy['nbrSuffragesRequis']),
'synthese_votants': int(sy['nombreVotants']),
'titre': json['titre'],
'type_code': json['typeVote']['codeTypeVote'],
'type_libelle': json['typeVote']['libelleTypeVote'],
'type_majorite': json['typeVote']['typeMajorite'],
}
scrutin = self.save(Scrutin, json['uid'], data)
def save_groupe(self, json):
cur = self.current
......@@ -71,7 +68,7 @@ class ImportScrutinsJob(BaseANJob):
groupe = ScrutinGroupe()
groupe.organe = self.get_cached(Organe, json['organeRef'])
groupe.organe = self.save(Organe, json['organeRef'])
groupe.nombre_membres = int(json['nombreMembresGroupe'])
vote = json['vote']
......@@ -97,8 +94,8 @@ class ImportScrutinsJob(BaseANJob):
for v in vs:
votants.append(Votant(position=pos,
acteur=self.get_cached(Acteur, v['acteurRef']),
mandat=self.get_cached(Mandat, v['mandatRef']),
acteur=self.save(Acteur, v['acteurRef']),
mandat=self.save(Mandat, v['mandatRef']),
cause=v.get('causePositionVote', None)))
groupe.votants = votants
......
......@@ -431,6 +431,7 @@ class Scrutin(db.Model):
__tablename__ = 'scrutins'
query_class = SearchableQuery
_last_modified = db.Column(db.DateTime)
id = db.Column(db.Unicode, primary_key=True)
numero = db.Column(db.Integer)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment