From 84112922558711c73a6338f14087c09cb1840c66 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 31 Aug 2022 12:02:19 +0200 Subject: [PATCH] =?UTF-8?q?=20-=20Export=20formations=20APC:=20parcours=20?= =?UTF-8?q?de=20module.=20=20-=20Nouvelles=20versions=20formations:=20pr?= =?UTF-8?q?=C3=A9serve=20parcours=20des=20modules.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/but_refcomp.py | 13 +++++++++---- app/models/modules.py | 1 + app/scodoc/sco_formations.py | 22 +++++++++++++++++++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/models/but_refcomp.py b/app/models/but_refcomp.py index e30d9988..ec16eeff 100644 --- a/app/models/but_refcomp.py +++ b/app/models/but_refcomp.py @@ -434,16 +434,21 @@ class ApcParcours(db.Model, XMLModel): cascade="all, delete-orphan", ) - def __repr__(self): + def __repr__(self) -> str: return f"<{self.__class__.__name__} {self.id} {self.code!r} ref={self.referentiel}>" - def to_dict(self): - return { + def to_dict(self, with_annees=True) -> dict: + """dict repr. + On peut ne pas indiquer les années pour gagner de la place (export formations). + """ + d = { "code": self.code, "numero": self.numero, "libelle": self.libelle, - "annees": {x.ordre: x.to_dict() for x in self.annees}, } + if with_annees: + d["annees"] = {x.ordre: x.to_dict() for x in self.annees} + return d class ApcAnneeParcours(db.Model, XMLModel): diff --git a/app/models/modules.py b/app/models/modules.py index d90019ba..082d5a93 100644 --- a/app/models/modules.py +++ b/app/models/modules.py @@ -142,6 +142,7 @@ class Module(db.Model): if coef != 0.0: ue = UniteEns.query.get(ue_id) ue_coef = ModuleUECoef(module=self, ue=ue, coef=coef) + db.session.add(ue_coef) self.ue_coefs.append(ue_coef) changed = True if changed: diff --git a/app/scodoc/sco_formations.py b/app/scodoc/sco_formations.py index e8aa9b96..24993922 100644 --- a/app/scodoc/sco_formations.py +++ b/app/scodoc/sco_formations.py @@ -33,6 +33,7 @@ import xml.dom.minidom import flask from flask import flash, g, url_for, request from flask_login import current_user +from app.models.but_refcomp import ApcParcours import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb @@ -145,6 +146,10 @@ def formation_export( {"ue_reference": str(ue_id), "coef": str(coef)} for (ue_id, coef) in module.get_ue_coef_dict().items() ] + # Et les parcours + mod["parcours"] = [ + p.to_dict(with_annees=False) for p in module.parcours + ] if not export_ids: del mod["id"] del mod["ue_id"] @@ -197,9 +202,8 @@ def formation_import_xml(doc: str, import_tags=True): ) from exc assert D[0] == "formation" F = D[1] - # F_quoted = F.copy() - # ndb.quote_dict(F_quoted) F["dept_id"] = g.scodoc_dept_id + referentiel_competence_id = F.get("referentiel_competence_id") # find new version number cnx = ndb.GetDBConnexion() cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) @@ -265,7 +269,7 @@ def formation_import_xml(doc: str, import_tags=True): if xml_module_id: modules_old2new[int(xml_module_id)] = mod_id if len(mod_info) > 2: - module = Module.query.get(mod_id) + module: Module = Module.query.get(mod_id) tag_names = [] ue_coef_dict = {} for child in mod_info[2]: @@ -275,6 +279,18 @@ def formation_import_xml(doc: str, import_tags=True): ue_reference = int(child[1]["ue_reference"]) coef = float(child[1]["coef"]) ue_coef_dict[ue_reference] = coef + elif child[0] == "parcours": + # associe les parcours de ce module (BUT) + code_parcours = child[1]["code"] + parcours = ApcParcours.query.filter_by( + code=code_parcours, + referentiel_id=referentiel_competence_id, + ).first() + if parcours: + module.parcours.append(parcours) + db.session.add(module) + else: + log("Warning: parcours {code_parcours} inexistant !") if import_tags and tag_names: sco_tag_module.module_tag_set(mod_id, tag_names) if module.is_apc() and ue_coef_dict: