1
0
forked from ScoDoc/ScoDoc

Verification et correction d'integrite semestre/UE/modules

This commit is contained in:
Emmanuel Viennet 2021-07-07 10:40:22 +02:00
parent 3bb69b4680
commit 2547868d2b

View File

@ -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)
+ "<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])
+ self.sco_footer(REQUEST)
)
H = [
self.sco_header(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
self.do_formsemestre_edit(sem)
H.append(
"""<p class="alert">Problème réparé: <a href="check_sem_integrity?formsemestre_id=%s">vérifiez maintenant</a></p>"""
% (formsemestre_id,)
)
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) + self.sco_footer(REQUEST)
security.declareProtected(ScoView, "check_form_integrity")