From 1b98e5f8ddde771acd5b8fcb8d8cb8e2dcc566c0 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 6 Jan 2022 21:23:29 +0100 Subject: [PATCH] Numeros ue et modules: invalide cache --- app/comp/moy_mod.py | 2 +- app/scodoc/sco_edit_formation.py | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/comp/moy_mod.py b/app/comp/moy_mod.py index 39de5a819..a75055b11 100644 --- a/app/comp/moy_mod.py +++ b/app/comp/moy_mod.py @@ -270,7 +270,7 @@ def load_evaluations_poids( remplies par default_poids. Résultat: (evals_poids, liste de UE du semestre) """ - modimpl = ModuleImpl.query.get(moduleimpl_id) + modimpl: ModuleImpl = ModuleImpl.query.get(moduleimpl_id) evaluations = Evaluation.query.filter_by(moduleimpl_id=moduleimpl_id).all() ues = modimpl.formsemestre.query_ues(with_sport=False).all() ue_ids = [ue.id for ue in ues] diff --git a/app/scodoc/sco_edit_formation.py b/app/scodoc/sco_edit_formation.py index 33390c1a1..38fed29c3 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -36,6 +36,7 @@ from app import log from app.models import SHORT_STR_LEN from app.models.formations import Formation from app.models.modules import Module +from app.models.ues import UniteEns import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu @@ -341,6 +342,7 @@ def module_move(module_id, after=0, redirect=True): db.session.add(module) db.session.add(neigh) db.session.commit() + module.formation.invalidate_cached_sems() # redirect to ue_list page: if redirect: return flask.redirect( @@ -355,16 +357,17 @@ def module_move(module_id, after=0, redirect=True): def ue_move(ue_id, after=0, redirect=1): """Move UE before/after previous one (decrement/increment numero)""" - o = sco_edit_ue.ue_list({"ue_id": ue_id})[0] - # log('ue_move %s (#%s) after=%s' % (ue_id, o['numero'], after)) + ue = UniteEns.query.get_or_404(ue_id) redirect = int(redirect) after = int(after) # 0: deplace avant, 1 deplace apres if after not in (0, 1): raise ValueError('invalid value for "after"') - formation_id = o["formation_id"] - others = sco_edit_ue.ue_list({"formation_id": formation_id}) + others = ue.formation.ues.order_by(UniteEns.numero).all() + if len({o.numero for o in others}) != len(others): + # il y a des numeros identiques ! + scu.objects_renumber(db, others) if len(others) > 1: - idx = [p["ue_id"] for p in others].index(ue_id) + idx = [u.id for u in others].index(ue.id) neigh = None # object to swap with if after == 0 and idx > 0: neigh = others[idx - 1] @@ -372,20 +375,19 @@ def ue_move(ue_id, after=0, redirect=1): neigh = others[idx + 1] if neigh: # # swap numero between partition and its neighbor - # log('moving ue %s (neigh #%s)' % (ue_id, neigh['numero'])) - cnx = ndb.GetDBConnexion() - o["numero"], neigh["numero"] = neigh["numero"], o["numero"] - if o["numero"] == neigh["numero"]: - neigh["numero"] -= 2 * after - 1 - sco_edit_ue._ueEditor.edit(cnx, o) - sco_edit_ue._ueEditor.edit(cnx, neigh) + ue.numero, neigh.numero = neigh.numero, ue.numero + db.session.add(ue) + db.session.add(neigh) + db.session.commit() + ue.formation.invalidate_cached_sems() + # redirect to ue_list page if redirect: return flask.redirect( url_for( "notes.ue_table", scodoc_dept=g.scodoc_dept, - formation_id=o["formation_id"], - semestre_idx=o["semestre_idx"], + formation_id=ue.formation_id, + semestre_idx=ue.semestre_idx, ) )