forked from ScoDoc/ScoDoc
API: fix /formsemestre/<int:formsemestre_id>/programme
This commit is contained in:
parent
8330ce66ca
commit
72e69960a4
@ -178,7 +178,7 @@ def dept_formsemestres_courants(acronym: str):
|
||||
FormSemestre.date_fin >= app.db.func.now(),
|
||||
)
|
||||
|
||||
return jsonify([d.to_dict(convert_parcours=True) for d in formsemestres])
|
||||
return jsonify([d.to_dict(convert_objects=True) for d in formsemestres])
|
||||
|
||||
|
||||
@bp.route("/departement/id/<int:dept_id>/formsemestres_courants", methods=["GET"])
|
||||
@ -198,4 +198,4 @@ def dept_formsemestres_courants_by_id(dept_id: int):
|
||||
FormSemestre.date_fin >= app.db.func.now(),
|
||||
)
|
||||
|
||||
return jsonify([d.to_dict(convert_parcours=True) for d in formsemestres])
|
||||
return jsonify([d.to_dict(convert_objects=True) for d in formsemestres])
|
||||
|
@ -217,7 +217,7 @@ def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None)
|
||||
formsemestres = query.order_by(FormSemestre.date_debut)
|
||||
|
||||
return jsonify(
|
||||
[formsemestre.to_dict(convert_parcours=True) for formsemestre in formsemestres]
|
||||
[formsemestre.to_dict(convert_objects=True) for formsemestre in formsemestres]
|
||||
)
|
||||
|
||||
|
||||
|
@ -215,12 +215,12 @@ def formsemestre_programme(formsemestre_id: int):
|
||||
ModuleType.STANDARD: [],
|
||||
}
|
||||
for modimpl in formsemestre.modimpls_sorted:
|
||||
d = modimpl.to_dict()
|
||||
d = modimpl.to_dict(convert_objects=True)
|
||||
m_list[modimpl.module.module_type].append(d)
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"ues": [ue.to_dict() for ue in ues],
|
||||
"ues": [ue.to_dict(convert_objects=True) for ue in ues],
|
||||
"ressources": m_list[ModuleType.RESSOURCE],
|
||||
"saes": m_list[ModuleType.SAE],
|
||||
"modules": m_list[ModuleType.STANDARD],
|
||||
|
@ -146,8 +146,11 @@ class FormSemestre(db.Model):
|
||||
def __repr__(self):
|
||||
return f"<{self.__class__.__name__} {self.id} {self.titre_num()}>"
|
||||
|
||||
def to_dict(self, convert_parcours=False):
|
||||
"dict (compatible ScoDoc7)"
|
||||
def to_dict(self, convert_objects=False) -> dict:
|
||||
"""dict (compatible ScoDoc7).
|
||||
If convert_objects, convert all attributes to native types
|
||||
(suitable jor json encoding).
|
||||
"""
|
||||
d = dict(self.__dict__)
|
||||
d.pop("_sa_instance_state", None)
|
||||
# ScoDoc7 output_formators: (backward compat)
|
||||
@ -165,7 +168,7 @@ class FormSemestre(db.Model):
|
||||
d["date_fin"] = d["date_fin_iso"] = ""
|
||||
d["responsables"] = [u.id for u in self.responsables]
|
||||
d["titre_formation"] = self.titre_formation()
|
||||
if convert_parcours:
|
||||
if convert_objects:
|
||||
d["parcours"] = [p.to_dict() for p in self.parcours]
|
||||
return d
|
||||
|
||||
|
@ -79,8 +79,11 @@ class ModuleImpl(db.Model):
|
||||
self.module.formation.get_module_coefs(self.module.semestre_id),
|
||||
)
|
||||
|
||||
def to_dict(self):
|
||||
"""as a dict, with the same conversions as in ScoDoc7, including module"""
|
||||
def to_dict(self, convert_objects=False):
|
||||
"""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)
|
||||
# ScoDoc7 output_formators: (backward compat)
|
||||
@ -88,7 +91,7 @@ class ModuleImpl(db.Model):
|
||||
e["ens"] = [
|
||||
{"moduleimpl_id": self.id, "ens_id": e.id} for e in self.enseignants
|
||||
]
|
||||
e["module"] = self.module.to_dict()
|
||||
e["module"] = self.module.to_dict(convert_objects=convert_objects)
|
||||
return e
|
||||
|
||||
|
||||
|
@ -67,9 +67,14 @@ 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):
|
||||
def to_dict(self, convert_objects=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)
|
||||
if convert_objects:
|
||||
e["parcours"] = [p.to_dict() for p in self.parcours]
|
||||
# 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
|
||||
@ -220,6 +225,14 @@ 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).
|
||||
"""
|
||||
d = dict(self.__dict__)
|
||||
d.pop("_sa_instance_state", None)
|
||||
return d
|
||||
|
||||
|
||||
class NotesTag(db.Model):
|
||||
"""Tag sur un module"""
|
||||
|
@ -59,18 +59,25 @@ class UniteEns(db.Model):
|
||||
self.semestre_idx} {
|
||||
'EXTERNE' if self.is_external else ''})>"""
|
||||
|
||||
def to_dict(self):
|
||||
def to_dict(self, convert_objects=False):
|
||||
"""as a dict, with the same conversions as in ScoDoc7
|
||||
(except ECTS: keep None)
|
||||
If convert_objects, convert all attributes to native types
|
||||
(suitable jor json encoding).
|
||||
"""
|
||||
e = dict(self.__dict__)
|
||||
e.pop("_sa_instance_state", None)
|
||||
e.pop("evaluation_ue_poids", None)
|
||||
# ScoDoc7 output_formators
|
||||
e["ue_id"] = self.id
|
||||
e["numero"] = e["numero"] if e["numero"] else 0
|
||||
e["ects"] = e["ects"]
|
||||
e["coefficient"] = e["coefficient"] if e["coefficient"] else 0.0
|
||||
e["code_apogee"] = e["code_apogee"] or "" # pas de None
|
||||
if convert_objects:
|
||||
e["module_ue_coefs"] = [
|
||||
c.to_dict(convert_objects=True) for c in self.module_ue_coefs
|
||||
]
|
||||
return e
|
||||
|
||||
def is_locked(self):
|
||||
|
Loading…
Reference in New Issue
Block a user