Commit f10262437933cc97c5aa3d1073d4088fdd1dafba

Authored by hitier
1 parent cf88ff52

Feed db periods and charges with lesia's

Showing 1 changed file with 28 additions and 8 deletions   Show diff stats
app/commands/commands.py
... ... @@ -35,36 +35,56 @@ def feed_from_lesia():
35 35  
36 36 # mapped classes are now created with names by default
37 37 # matching that of the table name.
38   - LesiaAgent = Base.classes.agent
39   - LesiaService = Base.classes.gestit_services
40   - LesiaProject = Base.classes.gestit_projets
41   - LesiaFonction = Base.classes.gestit_fonctions
  38 + lesia_agent = Base.classes.agent
  39 + lesia_service = Base.classes.gestit_services
  40 + lesia_project = Base.classes.gestit_projets
  41 + lesia_fonction = Base.classes.gestit_fonctions
  42 + lesia_affectation = Base.classes.gestit_affectations
  43 + lesia_periods = Base.classes.gestit_semestres
42 44  
43 45 lesia_session = Session(engine)
44   - agents = lesia_session.query(LesiaAgent).all()
  46 + agents = lesia_session.query(lesia_agent).all()
45 47 for a in agents:
46 48 n_a = Agent(firstname=a.nom, secondname=a.prenom)
47 49 db.session.add(n_a)
48 50 db.session.commit()
49 51  
50   - services = lesia_session.query(LesiaService).all()
  52 + services = lesia_session.query(lesia_service).all()
51 53 for s in services:
52 54 n_s = Service(name=s.nom)
53 55 db.session.add(n_s)
54 56 db.session.commit()
55 57  
56   - projects = lesia_session.query(LesiaProject).all()
  58 + projects = lesia_session.query(lesia_project).all()
57 59 for p in projects:
58 60 n_p = Project(name=p.nom)
59 61 db.session.add(n_p)
60 62 db.session.commit()
61 63  
62   - fonctions = lesia_session.query(LesiaFonction).all()
  64 + fonctions = lesia_session.query(lesia_fonction).all()
63 65 for f in fonctions:
64 66 n_c = Capacity(name=f.nom)
65 67 db.session.add(n_c)
66 68 db.session.commit()
67 69  
  70 + periods = lesia_session.query(lesia_periods)
  71 + for p in periods:
  72 + n_p = Period(name=p.id_semestre)
  73 + db.session.add(n_p)
  74 + db.session.commit()
  75 +
  76 + affectations = lesia_session.query(lesia_affectation)
  77 + for f in affectations:
  78 + p = Period.query.filter(Period.name == f.semestre_id).one()
  79 + n_c = Charge(agent_id=f.agent_id,
  80 + project_id=f.projet_id,
  81 + service_id=f.service_id,
  82 + capacity_id=f.fonction_id,
  83 + period_id=p.id,
  84 + charge_rate=f.charge)
  85 + db.session.add(n_c)
  86 + db.session.commit()
  87 +
68 88  
69 89 @bp.cli.command("feed_periods")
70 90 def feed_periods():
... ...