From f2e9fbb8cddaedfbb5e9f1b1b2f98bdfb6057f0c Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 8 Jan 2022 14:01:16 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20edition=20de=20formations=20migr?= =?UTF-8?q?=C3=A9es=20(non=20affichages=20de=20certains=20modules)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/formations.py | 14 +++++++++++--- app/models/ues.py | 5 ++++- app/scodoc/sco_edit_apc.py | 3 ++- app/scodoc/sco_edit_formation.py | 4 ++-- app/scodoc/sco_edit_ue.py | 6 +++--- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/models/formations.py b/app/models/formations.py index 3abbf3882..1dfd87285 100644 --- a/app/models/formations.py +++ b/app/models/formations.py @@ -97,14 +97,18 @@ class Formation(db.Model): for sem in self.formsemestres: sco_cache.invalidate_formsemestre(formsemestre_id=sem.id) - def force_semestre_modules_aux_ues(self) -> None: + def sanitize_old_formation(self) -> None: """ - Affecte à chaque module de cette formation le semestre de son UE de rattachement, + Corrige si nécessaire certains champs issus d'anciennes versions de ScoDoc: + - affecte à chaque module de cette formation le semestre de son UE de rattachement, si elle en a une. + - si le module_type n'est pas renseigné, le met à STANDARD. + Devrait être appelé lorsqu'on change le type de formation vers le BUT, et aussi lorsqu'on change le semestre d'une UE BUT. Utile pour la migration des anciennes formations vers le BUT. - Invalide les caches coefs/poids. + + En cas de changement, invalide les caches coefs/poids. """ if not self.is_apc(): return @@ -118,6 +122,10 @@ class Formation(db.Model): mod.semestre_id = mod.ue.semestre_idx db.session.add(mod) change = True + if mod.module_type is None: + mod.module_type = scu.ModuleType.STANDARD + db.session.add(mod) + change = True db.session.commit() if change: self.invalidate_module_coefs() diff --git a/app/models/ues.py b/app/models/ues.py index 5f99bdc28..26223eefc 100644 --- a/app/models/ues.py +++ b/app/models/ues.py @@ -46,7 +46,10 @@ class UniteEns(db.Model): modules = db.relationship("Module", lazy="dynamic", backref="ue") def __repr__(self): - return f"<{self.__class__.__name__}(id={self.id}, formation_id={self.formation_id}, acronyme='{self.acronyme}')>" + return f"""<{self.__class__.__name__}(id={self.id}, formation_id={ + self.formation_id}, acronyme='{self.acronyme}', semestre_idx={ + self.semestre_idx} { + 'EXTERNE' if self.is_external else ''})>""" def to_dict(self): """as a dict, with the same conversions as in ScoDoc7""" diff --git a/app/scodoc/sco_edit_apc.py b/app/scodoc/sco_edit_apc.py index 05b72b011..a9eff6de4 100644 --- a/app/scodoc/sco_edit_apc.py +++ b/app/scodoc/sco_edit_apc.py @@ -62,7 +62,8 @@ def html_edit_formation_apc( else: semestre_ids = [semestre_idx] other_modules = formation.modules.filter( - Module.module_type != ModuleType.SAE, Module.module_type != ModuleType.RESSOURCE + Module.module_type.is_distinct_from(ModuleType.SAE), + Module.module_type.is_distinct_from(ModuleType.RESSOURCE), ).order_by( Module.semestre_id, Module.module_type.desc(), Module.numero, Module.code ) diff --git a/app/scodoc/sco_edit_formation.py b/app/scodoc/sco_edit_formation.py index 33390c1a1..a126fcebf 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -304,9 +304,9 @@ def do_formation_edit(args): cnx = ndb.GetDBConnexion() sco_formations._formationEditor.edit(cnx, args) - formation = Formation.query.get(args["formation_id"]) + formation: Formation = Formation.query.get(args["formation_id"]) formation.invalidate_cached_sems() - formation.force_semestre_modules_aux_ues() + formation.sanitize_old_formation() def module_move(module_id, after=0, redirect=True): diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index 766fbd9b8..14f8a2c96 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -504,12 +504,12 @@ def ue_table(formation_id=None, semestre_idx=1, msg=""): # was ue_list """Liste des matières et modules d'une formation, avec liens pour éditer (si non verrouillée). """ - from app.scodoc import sco_formations from app.scodoc import sco_formsemestre_validation - formation = Formation.query.get(formation_id) + formation: Formation = Formation.query.get(formation_id) if not formation: raise ScoValueError("invalid formation_id") + formation.sanitize_old_formation() parcours = formation.get_parcours() is_apc = parcours.APC_SAE locked = formation.has_locked_sems() @@ -1205,7 +1205,7 @@ def do_ue_edit(args, bypass_lock=False, dont_invalidate_cache=False): if not dont_invalidate_cache: # Invalide les semestres utilisant cette formation: formation.invalidate_cached_sems() - formation.force_semestre_modules_aux_ues() + formation.sanitize_old_formation() # essai edition en ligne: From fbae5d268f55cb1dcba9c332c07dce681415201a Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 8 Jan 2022 15:27:40 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20exports=20bul.=20xml=20quand=20non?= =?UTF-8?q?=20publi=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/but/bulletin_but_xml_compat.py | 4 +++- app/scodoc/sco_bulletins_xml.py | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/but/bulletin_but_xml_compat.py b/app/but/bulletin_but_xml_compat.py index 10bec3d82..5b4a14ca0 100644 --- a/app/but/bulletin_but_xml_compat.py +++ b/app/but/bulletin_but_xml_compat.py @@ -117,7 +117,9 @@ def bulletin_but_xml_compat( ) # Disponible pour publication ? if not published: - return doc # stop ! + return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode( + scu.SCO_ENCODING + ) # stop ! # Moyenne générale: doc.append( Element( diff --git a/app/scodoc/sco_bulletins_xml.py b/app/scodoc/sco_bulletins_xml.py index bf9c63e98..6641c1785 100644 --- a/app/scodoc/sco_bulletins_xml.py +++ b/app/scodoc/sco_bulletins_xml.py @@ -93,9 +93,9 @@ def make_xml_formsemestre_bulletinetud( ) if (not sem["bul_hide_xml"]) or force_publishing: - published = "1" + published = 1 else: - published = "0" + published = 0 if xml_nodate: docdate = "" else: @@ -105,7 +105,7 @@ def make_xml_formsemestre_bulletinetud( "etudid": str(etudid), "formsemestre_id": str(formsemestre_id), "date": docdate, - "publie": published, + "publie": str(published), } if sem["etapes"]: el["etape_apo"] = str(sem["etapes"][0]) or "" @@ -141,7 +141,9 @@ def make_xml_formsemestre_bulletinetud( # Disponible pour publication ? if not published: - return doc # stop ! + return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode( + scu.SCO_ENCODING + ) # stop ! # Groupes: partitions = sco_groups.get_partitions_list(formsemestre_id, with_default=False)