API: fix /formsemestre/<int:formsemestre_id>/programme

This commit is contained in:
Emmanuel Viennet 2022-07-21 14:44:19 +02:00
parent 72e69960a4
commit d36a2950d3
3 changed files with 33 additions and 22 deletions

View File

@ -217,7 +217,6 @@ def formsemestre_programme(formsemestre_id: int):
for modimpl in formsemestre.modimpls_sorted:
d = modimpl.to_dict(convert_objects=True)
m_list[modimpl.module.module_type].append(d)
return jsonify(
{
"ues": [ue.to_dict(convert_objects=True) for ue in ues],

View File

@ -79,20 +79,23 @@ class ModuleImpl(db.Model):
self.module.formation.get_module_coefs(self.module.semestre_id),
)
def to_dict(self, convert_objects=False):
def to_dict(self, convert_objects=False, with_module=True):
"""as a dict, with the same conversions as in ScoDoc7, including module.
If convert_objects, convert all attributes to native types
(suitable jor json encoding).
"""
e = dict(self.__dict__)
e.pop("_sa_instance_state", None)
d = dict(self.__dict__)
d.pop("_sa_instance_state", None)
# ScoDoc7 output_formators: (backward compat)
e["moduleimpl_id"] = self.id
e["ens"] = [
d["moduleimpl_id"] = self.id
d["ens"] = [
{"moduleimpl_id": self.id, "ens_id": e.id} for e in self.enseignants
]
e["module"] = self.module.to_dict(convert_objects=convert_objects)
return e
if with_module:
d["module"] = self.module.to_dict(convert_objects=convert_objects)
else:
d.pop("module", None)
return d
# Enseignants (chargés de TD ou TP) d'un moduleimpl

View File

@ -67,24 +67,33 @@ class Module(db.Model):
def __repr__(self):
return f"<Module{ModuleType(self.module_type or ModuleType.STANDARD).name} id={self.id} code={self.code!r}>"
def to_dict(self, convert_objects=False) -> dict:
def to_dict(self, convert_objects=False, with_matiere=False, with_ue=False) -> dict:
"""If convert_objects, convert all attributes to native types
(suitable jor json encoding).
"""
e = dict(self.__dict__)
e.pop("_sa_instance_state", None)
d = dict(self.__dict__)
d.pop("_sa_instance_state", None)
if convert_objects:
e["parcours"] = [p.to_dict() for p in self.parcours]
d["parcours"] = [p.to_dict() for p in self.parcours]
if not with_matiere:
d.pop("matiere", None)
if not with_ue:
d.pop("ue", None)
if convert_objects and with_matiere:
d["matiere"] = self.matiere.to_dict(convert_objects=True)
if convert_objects and with_ue:
d["ue"] = self.ue.to_dict(convert_objects=True)
# ScoDoc7 output_formators: (backward compat)
e["module_id"] = self.id
e["heures_cours"] = 0.0 if self.heures_cours is None else self.heures_cours
e["heures_td"] = 0.0 if self.heures_td is None else self.heures_td
e["heures_tp"] = 0.0 if self.heures_tp is None else self.heures_tp
e["numero"] = 0 if self.numero is None else self.numero
e["coefficient"] = 0.0 if self.coefficient is None else self.coefficient
e["module_type"] = 0 if self.module_type is None else self.module_type
e["code_apogee"] = e["code_apogee"] or "" # pas de None
return e
d["module_id"] = self.id
d["heures_cours"] = 0.0 if self.heures_cours is None else self.heures_cours
d["heures_td"] = 0.0 if self.heures_td is None else self.heures_td
d["heures_tp"] = 0.0 if self.heures_tp is None else self.heures_tp
d["numero"] = 0 if self.numero is None else self.numero
d["coefficient"] = 0.0 if self.coefficient is None else self.coefficient
d["module_type"] = 0 if self.module_type is None else self.module_type
d["code_apogee"] = d["code_apogee"] or "" # pas de None
return d
def is_apc(self):
"True si module SAÉ ou Ressource"
@ -227,7 +236,7 @@ class ModuleUECoef(db.Model):
def to_dict(self, convert_objects=False) -> dict:
"""If convert_objects, convert all attributes to native types
(suitable jor json encoding).
(suitable for json encoding).
"""
d = dict(self.__dict__)
d.pop("_sa_instance_state", None)