- 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",
)
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):

View File

@ -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:

View File

@ -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: