From 3a56364bbdc682aae1a5840c6453fea94a2da1d2 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 7 Jul 2021 10:01:36 +0200 Subject: [PATCH] =?UTF-8?q?V=C3=A9rification=20et=20correction=20d'integri?= =?UTF-8?q?t=C3=A9=20semestre/UE/modules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_formsemestre_status.py | 2 +- app/views/notes.py | 56 +++++++++++++++++++++------ 2 files changed, 46 insertions(+), 12 deletions(-) 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"] - + "

Inconsistent UE/MOD:

" - + "
".join([str(x) for x in bad_ue]) - + "

Inconsistent SEM/MOD:

" - + "
".join([str(x) for x in bad_sem]) - + html_sco_header.sco_footer(context, REQUEST) - ) + H = [ + html_sco_header.sco_header(context, REQUEST=REQUEST), + "

formation_id=%s" % sem["formation_id"], + ] + if bad_ue: + H += [ + "

Modules d'une autre formation que leur UE:

", + "
".join([str(x) for x in bad_ue]), + ] + if bad_sem: + H += [ + "

Module du semestre dans une autre formation:

", + "
".join([str(x) for x in bad_sem]), + ] + if not bad_ue and not bad_sem: + H.append("

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")