Numeros ue et modules: invalide cache

This commit is contained in:
Emmanuel Viennet 2022-01-06 21:23:29 +01:00
parent 0098df4a8f
commit 1b98e5f8dd
2 changed files with 17 additions and 15 deletions

View File

@ -270,7 +270,7 @@ def load_evaluations_poids(
remplies par default_poids. remplies par default_poids.
Résultat: (evals_poids, liste de UE du semestre) 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() evaluations = Evaluation.query.filter_by(moduleimpl_id=moduleimpl_id).all()
ues = modimpl.formsemestre.query_ues(with_sport=False).all() ues = modimpl.formsemestre.query_ues(with_sport=False).all()
ue_ids = [ue.id for ue in ues] ue_ids = [ue.id for ue in ues]

View File

@ -36,6 +36,7 @@ from app import log
from app.models import SHORT_STR_LEN from app.models import SHORT_STR_LEN
from app.models.formations import Formation from app.models.formations import Formation
from app.models.modules import Module from app.models.modules import Module
from app.models.ues import UniteEns
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
import app.scodoc.sco_utils as scu 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(module)
db.session.add(neigh) db.session.add(neigh)
db.session.commit() db.session.commit()
module.formation.invalidate_cached_sems()
# redirect to ue_list page: # redirect to ue_list page:
if redirect: if redirect:
return flask.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): def ue_move(ue_id, after=0, redirect=1):
"""Move UE before/after previous one (decrement/increment numero)""" """Move UE before/after previous one (decrement/increment numero)"""
o = sco_edit_ue.ue_list({"ue_id": ue_id})[0] ue = UniteEns.query.get_or_404(ue_id)
# log('ue_move %s (#%s) after=%s' % (ue_id, o['numero'], after))
redirect = int(redirect) redirect = int(redirect)
after = int(after) # 0: deplace avant, 1 deplace apres after = int(after) # 0: deplace avant, 1 deplace apres
if after not in (0, 1): if after not in (0, 1):
raise ValueError('invalid value for "after"') raise ValueError('invalid value for "after"')
formation_id = o["formation_id"] others = ue.formation.ues.order_by(UniteEns.numero).all()
others = sco_edit_ue.ue_list({"formation_id": formation_id}) 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: 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 neigh = None # object to swap with
if after == 0 and idx > 0: if after == 0 and idx > 0:
neigh = others[idx - 1] neigh = others[idx - 1]
@ -372,20 +375,19 @@ def ue_move(ue_id, after=0, redirect=1):
neigh = others[idx + 1] neigh = others[idx + 1]
if neigh: # if neigh: #
# swap numero between partition and its neighbor # swap numero between partition and its neighbor
# log('moving ue %s (neigh #%s)' % (ue_id, neigh['numero'])) ue.numero, neigh.numero = neigh.numero, ue.numero
cnx = ndb.GetDBConnexion() db.session.add(ue)
o["numero"], neigh["numero"] = neigh["numero"], o["numero"] db.session.add(neigh)
if o["numero"] == neigh["numero"]: db.session.commit()
neigh["numero"] -= 2 * after - 1 ue.formation.invalidate_cached_sems()
sco_edit_ue._ueEditor.edit(cnx, o)
sco_edit_ue._ueEditor.edit(cnx, neigh)
# redirect to ue_list page # redirect to ue_list page
if redirect: if redirect:
return flask.redirect( return flask.redirect(
url_for( url_for(
"notes.ue_table", "notes.ue_table",
scodoc_dept=g.scodoc_dept, scodoc_dept=g.scodoc_dept,
formation_id=o["formation_id"], formation_id=ue.formation_id,
semestre_idx=o["semestre_idx"], semestre_idx=ue.semestre_idx,
) )
) )