From 7c7697631e5c2e5d88c964d62854cab005da8a51 Mon Sep 17 00:00:00 2001 From: Iziram Date: Wed, 5 Jun 2024 13:43:44 +0200 Subject: [PATCH] =?UTF-8?q?Assiduit=C3=A9=20:=20correction=20bug=20modulei?= =?UTF-8?q?mpls=20edit=5Fassiduite=5Fetud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/etudiants.py | 12 ++++++++++++ app/views/assiduites.py | 18 ++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/models/etudiants.py b/app/models/etudiants.py index 30e42d25..87ce6163 100644 --- a/app/models/etudiants.py +++ b/app/models/etudiants.py @@ -405,6 +405,18 @@ class Identite(models.ScoDocModel): modimpls_by_formsemestre[formsemestre.id] = modimpls_sem return modimpls_by_formsemestre + def get_modimpls_from_formsemestre( + self, formsemestre: "FormSemestre" + ) -> list["ModuleImpl"]: + """ + Liste des ModuleImpl auxquels l'étudiant est inscrit dans le formsemestre. + """ + modimpls = ModuleImpl.query.join(ModuleImplInscription).filter( + ModuleImplInscription.etudid == self.id, + ModuleImpl.formsemestre_id == formsemestre.id, + ) + return modimpls.all() + @classmethod def convert_dict_fields(cls, args: dict) -> dict: """Convert fields in the given dict. No other side effect. diff --git a/app/views/assiduites.py b/app/views/assiduites.py index 21f39f8c..f053a5f5 100644 --- a/app/views/assiduites.py +++ b/app/views/assiduites.py @@ -2168,17 +2168,19 @@ def edit_assiduite_etud(assiduite_id: int): form.disable_all() # peuplement moduleimpl_select - modimpls_by_formsemestre = etud.get_modimpls_by_formsemestre(scu.annee_scolaire()) choices: OrderedDict = OrderedDict() choices[""] = [("", "Non spécifié"), ("autre", "Autre module (pas dans la liste)")] - # indique le nom du semestre dans le menu (optgroup) - group_name: str = formsemestre.titre_annee() - choices[group_name] = [ - (m.id, f"{m.module.code} {m.module.abbrev or m.module.titre or ''}") - for m in modimpls_by_formsemestre[formsemestre.id] - if m.module.ue.type == UE_STANDARD - ] + # Récupération des modulesimpl du semestre si existant. + if formsemestre: + # indique le nom du semestre dans le menu (optgroup) + modimpls_from_formsemestre = etud.get_modimpls_from_formsemestre(formsemestre) + group_name: str = formsemestre.titre_annee() + choices[group_name] = [ + (m.id, f"{m.module.code} {m.module.abbrev or m.module.titre or ''}") + for m in modimpls_from_formsemestre + if m.module.ue.type == UE_STANDARD + ] choices.move_to_end("", last=False) form.modimpl.choices = choices