forked from ScoDoc/ScoDoc
Import/export xml des formations (format ScoDoc) avec coefs UE
This commit is contained in:
parent
5d8dad3711
commit
440e9157b4
@ -35,9 +35,10 @@ from flask import g, url_for, request
|
||||
from flask_login import current_user
|
||||
|
||||
import app.scodoc.sco_utils as scu
|
||||
|
||||
import app.scodoc.notesdb as ndb
|
||||
from app import db
|
||||
from app import log
|
||||
from app.models import Formation, Module
|
||||
from app.scodoc import sco_codes_parcours
|
||||
from app.scodoc import sco_edit_matiere
|
||||
from app.scodoc import sco_edit_module
|
||||
@ -103,7 +104,8 @@ def formation_export(
|
||||
"""Get a formation, with UE, matieres, modules
|
||||
in desired format
|
||||
"""
|
||||
F = formation_list(args={"formation_id": formation_id})[0]
|
||||
formation = Formation.query.get_or_404(formation_id)
|
||||
F = formation.to_dict()
|
||||
selector = {"formation_id": formation_id}
|
||||
if not export_external_ues:
|
||||
selector["is_external"] = False
|
||||
@ -111,7 +113,9 @@ def formation_export(
|
||||
F["ue"] = ues
|
||||
for ue in ues:
|
||||
ue_id = ue["ue_id"]
|
||||
ue["reference"] = ue_id # pour les coefficients
|
||||
if not export_ids:
|
||||
del ue["id"]
|
||||
del ue["ue_id"]
|
||||
del ue["formation_id"]
|
||||
if ue["ects"] is None:
|
||||
@ -121,17 +125,27 @@ def formation_export(
|
||||
for mat in mats:
|
||||
matiere_id = mat["matiere_id"]
|
||||
if not export_ids:
|
||||
del mat["id"]
|
||||
del mat["matiere_id"]
|
||||
del mat["ue_id"]
|
||||
mods = sco_edit_module.module_list({"matiere_id": matiere_id})
|
||||
mat["module"] = mods
|
||||
for mod in mods:
|
||||
module_id = mod["module_id"]
|
||||
if export_tags:
|
||||
# mod['tags'] = sco_tag_module.module_tag_list( module_id=mod['module_id'])
|
||||
tags = sco_tag_module.module_tag_list(module_id=mod["module_id"])
|
||||
if tags:
|
||||
mod["tags"] = [{"name": x} for x in tags]
|
||||
#
|
||||
module = Module.query.get(module_id)
|
||||
if module.is_apc():
|
||||
# Exporte les coefficients
|
||||
mod["coefficients"] = [
|
||||
{"ue_reference": str(ue_id), "coef": str(coef)}
|
||||
for (ue_id, coef) in module.get_ue_coef_dict().items()
|
||||
]
|
||||
if not export_ids:
|
||||
del mod["id"]
|
||||
del mod["ue_id"]
|
||||
del mod["matiere_id"]
|
||||
del mod["module_id"]
|
||||
@ -197,6 +211,9 @@ def formation_import_xml(doc: str, import_tags=True):
|
||||
ues_old2new = {} # xml ue_id : new ue_id
|
||||
modules_old2new = {} # xml module_id : new module_id
|
||||
# (nb: mecanisme utilise pour cloner semestres seulement, pas pour I/O XML)
|
||||
|
||||
ue_reference_to_id = {} # pour les coefs APC (map reference -> ue_id)
|
||||
modules_a_coefficienter = [] # Liste des modules avec coefs APC
|
||||
# -- create UEs
|
||||
for ue_info in D[2]:
|
||||
assert ue_info[0] == "ue"
|
||||
@ -209,6 +226,9 @@ def formation_import_xml(doc: str, import_tags=True):
|
||||
ue_id = sco_edit_ue.do_ue_create(ue_info[1])
|
||||
if xml_ue_id:
|
||||
ues_old2new[xml_ue_id] = ue_id
|
||||
ue_reference = int(ue_info[1].get("reference"))
|
||||
if ue_reference:
|
||||
ue_reference_to_id[ue_reference] = ue_id
|
||||
# -- create matieres
|
||||
for mat_info in ue_info[2]:
|
||||
assert mat_info[0] == "matiere"
|
||||
@ -228,11 +248,27 @@ def formation_import_xml(doc: str, import_tags=True):
|
||||
mod_id = sco_edit_module.do_module_create(mod_info[1])
|
||||
if xml_module_id:
|
||||
modules_old2new[int(xml_module_id)] = mod_id
|
||||
if import_tags:
|
||||
if len(mod_info) > 2:
|
||||
tag_names = [t[1]["name"] for t in mod_info[2]]
|
||||
module = Module.query.get(mod_id)
|
||||
tag_names = []
|
||||
ue_coef_dict = {}
|
||||
for child in mod_info[2]:
|
||||
if child[0] == "tags" and import_tags:
|
||||
tag_names.append(child[1]["name"])
|
||||
elif child[0] == "coefficients":
|
||||
ue_reference = int(child[1]["ue_reference"])
|
||||
coef = float(child[1]["coef"])
|
||||
ue_coef_dict[ue_reference] = coef
|
||||
if import_tags and tag_names:
|
||||
sco_tag_module.module_tag_set(mod_id, tag_names)
|
||||
|
||||
if module.is_apc() and ue_coef_dict:
|
||||
modules_a_coefficienter.append((module, ue_coef_dict))
|
||||
# Fixe les coefs APC (à la fin pour que les UE soient crées)
|
||||
for module, ue_coef_dict_ref in modules_a_coefficienter:
|
||||
# remap ue ids:
|
||||
ue_coef_dict = {ue_reference_to_id[k]: v for (k, v) in ue_coef_dict_ref.items()}
|
||||
module.set_ue_coef_dict(ue_coef_dict)
|
||||
db.session.commit()
|
||||
return formation_id, modules_old2new, ues_old2new
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user