diff --git a/ZNotes.py b/ZNotes.py index 59106cbfe..8d8bfa7a9 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"] - + "
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 + 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")