diff --git a/app/but/bulletin_but_xml_compat.py b/app/but/bulletin_but_xml_compat.py index 5f31aa90..9b0996c1 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/models/formations.py b/app/models/formations.py index 3abbf388..1dfd8728 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 5f99bdc2..26223eef 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_bulletins_xml.py b/app/scodoc/sco_bulletins_xml.py index 570cafaa..aa2b9577 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) diff --git a/app/scodoc/sco_edit_apc.py b/app/scodoc/sco_edit_apc.py index 05b72b01..a9eff6de 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 38fed29c..317e3e8b 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -305,9 +305,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 a98780e2..f2c5d6cd 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() @@ -1209,7 +1209,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: