From f10262437933cc97c5aa3d1073d4088fdd1dafba Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Sat, 3 Apr 2021 00:08:55 +0200 Subject: [PATCH] Feed db periods and charges with lesia's --- app/commands/commands.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/app/commands/commands.py b/app/commands/commands.py index 3a2d1ab..415c5d7 100644 --- a/app/commands/commands.py +++ b/app/commands/commands.py @@ -35,36 +35,56 @@ def feed_from_lesia(): # mapped classes are now created with names by default # matching that of the table name. - LesiaAgent = Base.classes.agent - LesiaService = Base.classes.gestit_services - LesiaProject = Base.classes.gestit_projets - LesiaFonction = Base.classes.gestit_fonctions + lesia_agent = Base.classes.agent + lesia_service = Base.classes.gestit_services + lesia_project = Base.classes.gestit_projets + lesia_fonction = Base.classes.gestit_fonctions + lesia_affectation = Base.classes.gestit_affectations + lesia_periods = Base.classes.gestit_semestres lesia_session = Session(engine) - agents = lesia_session.query(LesiaAgent).all() + agents = lesia_session.query(lesia_agent).all() for a in agents: n_a = Agent(firstname=a.nom, secondname=a.prenom) db.session.add(n_a) db.session.commit() - services = lesia_session.query(LesiaService).all() + services = lesia_session.query(lesia_service).all() for s in services: n_s = Service(name=s.nom) db.session.add(n_s) db.session.commit() - projects = lesia_session.query(LesiaProject).all() + projects = lesia_session.query(lesia_project).all() for p in projects: n_p = Project(name=p.nom) db.session.add(n_p) db.session.commit() - fonctions = lesia_session.query(LesiaFonction).all() + fonctions = lesia_session.query(lesia_fonction).all() for f in fonctions: n_c = Capacity(name=f.nom) db.session.add(n_c) db.session.commit() + periods = lesia_session.query(lesia_periods) + for p in periods: + n_p = Period(name=p.id_semestre) + db.session.add(n_p) + db.session.commit() + + affectations = lesia_session.query(lesia_affectation) + for f in affectations: + p = Period.query.filter(Period.name == f.semestre_id).one() + n_c = Charge(agent_id=f.agent_id, + project_id=f.projet_id, + service_id=f.service_id, + capacity_id=f.fonction_id, + period_id=p.id, + charge_rate=f.charge) + db.session.add(n_c) + db.session.commit() + @bp.cli.command("feed_periods") def feed_periods(): -- libgit2 0.21.2