From 2547868d2bc30f55b9c8615aee13a64e06d1acd6 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 7 Jul 2021 10:40:22 +0200 Subject: [PATCH] Verification et correction d'integrite semestre/UE/modules --- ZNotes.py | 66 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/ZNotes.py b/ZNotes.py index 59106cbf..8d8bfa7a 100644 --- a/ZNotes.py +++ b/ZNotes.py @@ -3159,22 +3159,23 @@ class ZNotes(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Impl # -------------------------------------------------------------------- # DEBUG - security.declareProtected(ScoView, "check_sem_integrity") + security.declareProtected(ScoImplement, "check_sem_integrity") - def check_sem_integrity(self, formsemestre_id, REQUEST): + def check_sem_integrity(self, formsemestre_id, REQUEST, fix=False): """Debug. Check that ue and module formations are consistents """ sem = sco_formsemestre.get_formsemestre(self, formsemestre_id) - modimpls = sco_moduleimpl.do_moduleimpl_list( - self, formsemestre_id=formsemestre_id - ) + modimpls = self.do_moduleimpl_list(formsemestre_id=formsemestre_id) bad_ue = [] bad_sem = [] + formations_set = set() # les formations mentionnées dans les UE et modules for modimpl in modimpls: mod = self.do_module_list({"module_id": modimpl["module_id"]})[0] + formations_set.add(mod["formation_id"]) ue = self.do_ue_list({"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 @@ -3183,15 +3184,52 @@ class ZNotes(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Impl bad_sem.append(modimpl) modimpl["mod"] = mod - return ( - self.sco_header(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]) - + self.sco_footer(REQUEST) - ) + H = [ + self.sco_header(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 + self.do_formsemestre_edit(sem) + H.append( + """

Problème réparé: vérifiez maintenant

""" + % (formsemestre_id,) + ) + 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) + self.sco_footer(REQUEST) security.declareProtected(ScoView, "check_form_integrity")