Vérification et correction d'integrité semestre/UE/modules

This commit is contained in:
Emmanuel Viennet 2021-07-07 10:01:36 +02:00
parent d64e6632f0
commit 3a56364bbd
2 changed files with 46 additions and 12 deletions

View File

@ -261,7 +261,7 @@ def formsemestre_status_menubar(context, sem, REQUEST):
if current_app.config["ENV"] == "development":
menuSemestre.append(
{
"title": "Check integrity",
"title": "Vérifier l'intégrité",
"endpoint": "notes.check_sem_integrity",
"args": {"formsemestre_id": formsemestre_id},
"enabled": True,

View File

@ -2410,9 +2410,9 @@ sco_publish(
@bp.route("/check_sem_integrity")
@permission_required(Permission.ScoView)
@permission_required(Permission.ScoImplement)
@scodoc7func(context)
def check_sem_integrity(context, formsemestre_id, REQUEST):
def check_sem_integrity(context, formsemestre_id, REQUEST, fix=False):
"""Debug.
Check that ue and module formations are consistents
"""
@ -2423,11 +2423,14 @@ def check_sem_integrity(context, formsemestre_id, REQUEST):
)
bad_ue = []
bad_sem = []
formations_set = set() # les formations mentionnées dans les UE et modules
for modimpl in modimpls:
mod = sco_edit_module.do_module_list(
context, {"module_id": modimpl["module_id"]}
)[0]
formations_set.add(mod["formation_id"])
ue = sco_edit_ue.do_ue_list(context, {"ue_id": mod["ue_id"]})[0]
formations_set.add(ue["formation_id"])
if ue["formation_id"] != mod["formation_id"]:
modimpl["mod"] = mod
modimpl["ue"] = ue
@ -2436,15 +2439,46 @@ def check_sem_integrity(context, formsemestre_id, REQUEST):
bad_sem.append(modimpl)
modimpl["mod"] = mod
return (
html_sco_header.sco_header(context, REQUEST=REQUEST)
+ "<p>formation_id=%s" % sem["formation_id"]
+ "<h2>Inconsistent UE/MOD:</h2>"
+ "<br/>".join([str(x) for x in bad_ue])
+ "<h2>Inconsistent SEM/MOD:</h2>"
+ "<br/>".join([str(x) for x in bad_sem])
+ html_sco_header.sco_footer(context, REQUEST)
)
H = [
html_sco_header.sco_header(context, REQUEST=REQUEST),
"<p>formation_id=%s" % sem["formation_id"],
]
if bad_ue:
H += [
"<h2>Modules d'une autre formation que leur UE:</h2>",
"<br/>".join([str(x) for x in bad_ue]),
]
if bad_sem:
H += [
"<h2>Module du semestre dans une autre formation:</h2>",
"<br/>".join([str(x) for x in bad_sem]),
]
if not bad_ue and not bad_sem:
H.append("<p>Aucun problème à signaler !</p>")
else:
log("check_sem_integrity: problem detected: formations_set=%s" % formations_set)
if sem["formation_id"] in formations_set:
formations_set.remove(sem["formation_id"])
if len(formations_set) == 1:
if fix:
log("check_sem_integrity: trying to fix %s" % formsemestre_id)
formation_id = formations_set.pop()
if sem["formation_id"] != formation_id:
sem["formation_id"] = formation_id
sco_formsemestre.do_formsemestre_edit(context, sem)
H.append("""<p class="alert">Problème réparé: vérifiez</p>""")
else:
H.append(
"""
<p class="alert">Problème détecté réparable:
<a href="check_sem_integrity?formsemestre_id=%s&fix=1">réparer maintenant</a></p>
"""
% (formsemestre_id,)
)
else:
H.append("""<p class="alert">Problème détecté !</p>""")
return "\n".join(H) + html_sco_header.sco_footer(context, REQUEST)
@bp.route("/check_form_integrity")