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.
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]

View File

@ -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,
)
)