forked from ScoDoc/ScoDoc
Export formation: fix regression and sort xml attributes to get stable results
This commit is contained in:
parent
8feff2b182
commit
abd8bf484d
@ -125,7 +125,7 @@ def formation_export_dict(
|
|||||||
mat = db.session.get(Matiere, matiere_id)
|
mat = db.session.get(Matiere, matiere_id)
|
||||||
mods = mat.modules.all()
|
mods = mat.modules.all()
|
||||||
mods.sort(key=lambda m: (m.numero, m.code))
|
mods.sort(key=lambda m: (m.numero, m.code))
|
||||||
mat_d["module"] = [mod.to_dict() for mod in mods]
|
mat_d["module"] = [mod.to_dict(convert_objects=True) for mod in mods]
|
||||||
for module, mod_d in zip(mods, mat_d["module"]):
|
for module, mod_d in zip(mods, mat_d["module"]):
|
||||||
if export_tags:
|
if export_tags:
|
||||||
tags = [t.title for t in module.tags]
|
tags = [t.title for t in module.tags]
|
||||||
@ -228,11 +228,10 @@ def _formation_retreive_refcomp(f_dict: dict) -> int:
|
|||||||
).first()
|
).first()
|
||||||
if refcomp:
|
if refcomp:
|
||||||
return refcomp.id
|
return refcomp.id
|
||||||
else:
|
flash(
|
||||||
flash(
|
f"""Impossible de trouver le référentiel de compétence pour {
|
||||||
f"""Impossible de trouver le référentiel de compétence pour {
|
refcomp_specialite} : est-il chargé ?"""
|
||||||
refcomp_specialite} : est-il chargé ?"""
|
)
|
||||||
)
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,24 +107,20 @@ def _dictlist2xml(dictlist, root=None, tagname=None, quote=False):
|
|||||||
elem.set("code", _repr_as_xml(d))
|
elem.set("code", _repr_as_xml(d))
|
||||||
else:
|
else:
|
||||||
if quote:
|
if quote:
|
||||||
d_scalar = dict(
|
d_scalar = {
|
||||||
[
|
k: quote_xml_attr(_repr_as_xml(v))
|
||||||
(k, quote_xml_attr(_repr_as_xml(v)))
|
for (k, v) in d.items()
|
||||||
for (k, v) in d.items()
|
if isinstance(v, scalar_types)
|
||||||
if isinstance(v, scalar_types)
|
}
|
||||||
]
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
d_scalar = dict(
|
d_scalar = {
|
||||||
[
|
k: _repr_as_xml(v)
|
||||||
(k, _repr_as_xml(v))
|
for (k, v) in d.items()
|
||||||
for (k, v) in d.items()
|
if isinstance(v, scalar_types)
|
||||||
if isinstance(v, scalar_types)
|
}
|
||||||
]
|
for k, v in sorted(d_scalar.items()):
|
||||||
)
|
elem.set(k, v)
|
||||||
for k in d_scalar:
|
d_list = {k: v for (k, v) in d.items() if isinstance(v, list)}
|
||||||
elem.set(k, d_scalar[k])
|
|
||||||
d_list = dict([(k, v) for (k, v) in d.items() if isinstance(v, list)])
|
|
||||||
if d_list:
|
if d_list:
|
||||||
for k, v in d_list.items():
|
for k, v in d_list.items():
|
||||||
_dictlist2xml(v, tagname=k, root=elem, quote=quote)
|
_dictlist2xml(v, tagname=k, root=elem, quote=quote)
|
||||||
|
Loading…
Reference in New Issue
Block a user