diff --git a/app/models/modules.py b/app/models/modules.py index 8f305507..24e55246 100644 --- a/app/models/modules.py +++ b/app/models/modules.py @@ -129,9 +129,27 @@ class Module(db.Model): # à redéfinir les relationships... return sorted(self.ue_coefs, key=lambda x: x.ue.numero) - def ue_coefs_descr(self): - """List of tuples [ (ue_acronyme, coef) ]""" - return [(c.ue.acronyme, c.coef) for c in self.get_ue_coefs_sorted()] + def ue_coefs_list(self, include_zeros=True): + """Liste des coefs vers les UE (pour les modules APC). + Si include_zeros, liste aussi les UE sans coef (donc nul) de ce semestre. + Result: List of tuples [ (ue, coef) ] + """ + if not self.is_apc(): + return [] + if include_zeros: + # Toutes les UE du même semestre: + ues_semestre = ( + self.formation.ues.filter_by(semestre_idx=self.ue.semestre_idx) + .order_by(UniteEns.numero) + .all() + ) + coefs_dict = self.get_ue_coef_dict() + coefs_list = [] + for ue in ues_semestre: + coefs_list.append((ue, coefs_dict.get(ue.id, 0.0))) + return coefs_list + # Liste seulement les coefs définis: + return [(c.ue, c.coef) for c in self.get_ue_coefs_sorted()] class ModuleUECoef(db.Model): diff --git a/app/scodoc/sco_edit_module.py b/app/scodoc/sco_edit_module.py index 813320d5..fbc28db6 100644 --- a/app/scodoc/sco_edit_module.py +++ b/app/scodoc/sco_edit_module.py @@ -554,9 +554,11 @@ def module_edit(module_id=None): ), ] if is_apc: - coefs_descr = a_module.ue_coefs_descr() - if coefs_descr: - coefs_descr_txt = ", ".join(["%s: %s" % x for x in coefs_descr]) + coefs_lst = a_module.ue_coefs_list() + if coefs_lst: + coefs_descr_txt = ", ".join( + [f"{ue.acronyme}: {c}" for (ue, c) in coefs_lst] + ) else: coefs_descr_txt = """non définis""" descr += [ diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index 5c318989..7ca52926 100644 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -1119,7 +1119,7 @@ def formsemestre_tableau_modules( mod_descr = "Module " + (mod.titre or "") if mod.is_apc(): coef_descr = ", ".join( - [f"{ue_acro}: {co}" for ue_acro, co in mod.ue_coefs_descr()] + [f"{ue.acronyme}: {co}" for ue, co in mod.ue_coefs_list()] ) if coef_descr: mod_descr += " Coefs: " + coef_descr diff --git a/app/scodoc/sco_moduleimpl_status.py b/app/scodoc/sco_moduleimpl_status.py index 33f51da1..735ece8a 100644 --- a/app/scodoc/sco_moduleimpl_status.py +++ b/app/scodoc/sco_moduleimpl_status.py @@ -156,28 +156,29 @@ def moduleimpl_evaluation_menu(evaluation_id, nbnotes=0): return htmlutils.make_menu("actions", menuEval, alone=True) -def _ue_coefs_html(coefs_descr) -> str: +def _ue_coefs_html(coefs_lst) -> str: """ """ - max_coef = max([x[1] for x in coefs_descr]) if coefs_descr else 1.0 + max_coef = max([x[1] for x in coefs_lst]) if coefs_lst else 1.0 H = """