diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index abd019c9c..19ef67dfb 100644 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -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, diff --git a/app/views/notes.py b/app/views/notes.py index 3b214c482..f5e95d35b 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -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) - + "
formation_id=%s" % sem["formation_id"] - + "
formation_id=%s" % sem["formation_id"], + ] + if bad_ue: + H += [ + "
Aucun problème à signaler !
") + 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("""Problème réparé: vérifiez
""") + else: + H.append( + """ +Problème détecté réparable: + réparer maintenant
+ """ + % (formsemestre_id,) + ) + else: + H.append("""Problème détecté !
""") + + return "\n".join(H) + html_sco_header.sco_footer(context, REQUEST) @bp.route("/check_form_integrity")