From cef298cfbea184c9351849740a8d59c92906cc68 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 20 Mar 2023 17:17:39 +0100 Subject: [PATCH] =?UTF-8?q?Optim:=20retire=20ann=C3=A9es=20de=20parcours?= =?UTF-8?q?=20de=20ue.to=5Fdict()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/comp/res_common.py | 9 ++++++--- app/models/ues.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/comp/res_common.py b/app/comp/res_common.py index a9459caf..dee90eb0 100644 --- a/app/comp/res_common.py +++ b/app/comp/res_common.py @@ -87,6 +87,7 @@ class ResultatsSemestre(ResultatsCache): self.autorisations_inscription = None self.moyennes_matieres = {} """Moyennes de matières, si calculées. { matiere_id : Series, index etudid }""" + # self._ues_by_id_cache: dict[int, UniteEns] = {} # per-instance cache def __repr__(self): return f"<{self.__class__.__name__}(formsemestre='{self.formsemestre}')>" @@ -341,7 +342,9 @@ class ResultatsSemestre(ResultatsCache): """L'état de l'UE pour cet étudiant. Result: dict, ou None si l'UE n'est pas dans ce semestre. """ - ue = UniteEns.query.get(ue_id) + ue: UniteEns = UniteEns.query.get(ue_id) + ue_dict = ue.to_dict() + if ue.type == UE_SPORT: return { "is_capitalized": False, @@ -351,7 +354,7 @@ class ResultatsSemestre(ResultatsCache): "cur_moy_ue": 0.0, "moy": 0.0, "event_date": None, - "ue": ue.to_dict(), + "ue": ue_dict, "formsemestre_id": None, "capitalized_ue_id": None, "ects_pot": 0.0, @@ -420,7 +423,7 @@ class ResultatsSemestre(ResultatsCache): "cur_moy_ue": cur_moy_ue, "moy": moy_ue, "event_date": ue_cap["event_date"] if is_capitalized else None, - "ue": ue.to_dict(), + "ue": ue_dict, "formsemestre_id": ue_cap["formsemestre_id"] if is_capitalized else None, "capitalized_ue_id": ue_cap["ue_id"] if is_capitalized else None, } diff --git a/app/models/ues.py b/app/models/ues.py index faa5df20..caa46ce4 100644 --- a/app/models/ues.py +++ b/app/models/ues.py @@ -104,7 +104,7 @@ class UniteEns(db.Model): """as a dict, with the same conversions as in ScoDoc7 (except ECTS: keep None) If convert_objects, convert all attributes to native types - (suitable jor json encoding). + (suitable for json encoding). """ e = dict(self.__dict__) e.pop("_sa_instance_state", None) @@ -115,7 +115,7 @@ class UniteEns(db.Model): e["ects"] = e["ects"] e["coefficient"] = e["coefficient"] if e["coefficient"] else 0.0 e["code_apogee"] = e["code_apogee"] or "" # pas de None - e["parcour"] = self.parcour.to_dict() if self.parcour else None + e["parcour"] = self.parcour.to_dict(with_annees=False) if self.parcour else None if with_module_ue_coefs: if convert_objects: e["module_ue_coefs"] = [