- Export formations APC: parcours de module.

- Nouvelles versions formations: préserve parcours des modules.
This commit is contained in:
Emmanuel Viennet 2022-08-31 12:02:19 +02:00
parent b8cf116fc6
commit 8411292255
3 changed files with 29 additions and 7 deletions

View File

@ -434,16 +434,21 @@ class ApcParcours(db.Model, XMLModel):
cascade="all, delete-orphan", cascade="all, delete-orphan",
) )
def __repr__(self): def __repr__(self) -> str:
return f"<{self.__class__.__name__} {self.id} {self.code!r} ref={self.referentiel}>" return f"<{self.__class__.__name__} {self.id} {self.code!r} ref={self.referentiel}>"
def to_dict(self): def to_dict(self, with_annees=True) -> dict:
return { """dict repr.
On peut ne pas indiquer les années pour gagner de la place (export formations).
"""
d = {
"code": self.code, "code": self.code,
"numero": self.numero, "numero": self.numero,
"libelle": self.libelle, "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): class ApcAnneeParcours(db.Model, XMLModel):

View File

@ -142,6 +142,7 @@ class Module(db.Model):
if coef != 0.0: if coef != 0.0:
ue = UniteEns.query.get(ue_id) ue = UniteEns.query.get(ue_id)
ue_coef = ModuleUECoef(module=self, ue=ue, coef=coef) ue_coef = ModuleUECoef(module=self, ue=ue, coef=coef)
db.session.add(ue_coef)
self.ue_coefs.append(ue_coef) self.ue_coefs.append(ue_coef)
changed = True changed = True
if changed: if changed:

View File

@ -33,6 +33,7 @@ import xml.dom.minidom
import flask import flask
from flask import flash, g, url_for, request from flask import flash, g, url_for, request
from flask_login import current_user from flask_login import current_user
from app.models.but_refcomp import ApcParcours
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
@ -145,6 +146,10 @@ def formation_export(
{"ue_reference": str(ue_id), "coef": str(coef)} {"ue_reference": str(ue_id), "coef": str(coef)}
for (ue_id, coef) in module.get_ue_coef_dict().items() 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: if not export_ids:
del mod["id"] del mod["id"]
del mod["ue_id"] del mod["ue_id"]
@ -197,9 +202,8 @@ def formation_import_xml(doc: str, import_tags=True):
) from exc ) from exc
assert D[0] == "formation" assert D[0] == "formation"
F = D[1] F = D[1]
# F_quoted = F.copy()
# ndb.quote_dict(F_quoted)
F["dept_id"] = g.scodoc_dept_id F["dept_id"] = g.scodoc_dept_id
referentiel_competence_id = F.get("referentiel_competence_id")
# find new version number # find new version number
cnx = ndb.GetDBConnexion() cnx = ndb.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
@ -265,7 +269,7 @@ def formation_import_xml(doc: str, import_tags=True):
if xml_module_id: if xml_module_id:
modules_old2new[int(xml_module_id)] = mod_id modules_old2new[int(xml_module_id)] = mod_id
if len(mod_info) > 2: if len(mod_info) > 2:
module = Module.query.get(mod_id) module: Module = Module.query.get(mod_id)
tag_names = [] tag_names = []
ue_coef_dict = {} ue_coef_dict = {}
for child in mod_info[2]: 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"]) ue_reference = int(child[1]["ue_reference"])
coef = float(child[1]["coef"]) coef = float(child[1]["coef"])
ue_coef_dict[ue_reference] = 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: if import_tags and tag_names:
sco_tag_module.module_tag_set(mod_id, tag_names) sco_tag_module.module_tag_set(mod_id, tag_names)
if module.is_apc() and ue_coef_dict: if module.is_apc() and ue_coef_dict: