Modification de /formsemestre/<int:formsemestre_id>/etudiants[/long]

Voir ligne 45 du tableur.

 - Ajout de la forme /long (permet d'avoir entre autre la date de naissance)
 - Ajout de la clé de tri (sort_key)
 - Résultat trié alphabétiquement.

Exemple: pour 84 étudiants, on a une réponse de 105KB en format normal (short), et 230KB en format "long".
This commit is contained in:
Emmanuel Viennet 2022-08-30 19:13:21 +02:00
parent 7f707d5a4c
commit 42f0cb8e76
2 changed files with 31 additions and 8 deletions

View File

@ -253,24 +253,42 @@ def formsemestre_programme(formsemestre_id: int):
@bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants",
defaults={"with_query": False},
defaults={"with_query": False, "long": False},
)
@bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/long",
defaults={"with_query": False, "long": True},
)
@bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/query",
defaults={"with_query": True},
defaults={"with_query": True, "long": False},
)
@bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/long/query",
defaults={"with_query": True, "long": True},
)
@api_web_bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants",
defaults={"with_query": False},
defaults={"with_query": False, "long": False},
)
@api_web_bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/long",
defaults={"with_query": False, "long": True},
)
@api_web_bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/query",
defaults={"with_query": True},
defaults={"with_query": True, "long": False},
)
@api_web_bp.route(
"/formsemestre/<int:formsemestre_id>/etudiants/long/query",
defaults={"with_query": True, "long": True},
)
@login_required
@scodoc
@permission_required(Permission.ScoView)
def formsemestre_etudiants(formsemestre_id: int, with_query: bool = False):
def formsemestre_etudiants(
formsemestre_id: int, with_query: bool = False, long: bool = False
):
"""Etudiants d'un formsemestre."""
query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept:
@ -292,7 +310,10 @@ def formsemestre_etudiants(formsemestre_id: int, with_query: bool = False):
else:
inscriptions = formsemestre.inscriptions
etuds = [ins.etud.to_dict_short() for ins in inscriptions]
if long:
etuds = [ins.etud.to_dict_api() for ins in inscriptions]
else:
etuds = [ins.etud.to_dict_short() for ins in inscriptions]
# Ajout des groupes de chaque étudiants
# XXX A REVOIR: trop inefficace !
for etud in etuds:
@ -300,7 +321,7 @@ def formsemestre_etudiants(formsemestre_id: int, with_query: bool = False):
etud["id"], formsemestre_id, exclude_default=True
)
return jsonify(etuds)
return jsonify(sorted(etuds, key=lambda e: e["sort_key"]))
@bp.route("/formsemestre/<int:formsemestre_id>/etat_evals")

View File

@ -149,13 +149,14 @@ class Identite(db.Model):
"""Les champs essentiels"""
return {
"id": self.id,
"civilite": self.civilite,
"code_nip": self.code_nip,
"code_ine": self.code_ine,
"dept_id": self.dept_id,
"nom": self.nom,
"nom_usuel": self.nom_usuel,
"prenom": self.prenom,
"civilite": self.civilite,
"sort_key": self.sort_key,
}
def to_dict_scodoc7(self) -> dict:
@ -217,6 +218,7 @@ class Identite(db.Model):
e["adresses"] = [adr.to_dict() for adr in self.adresses]
e["dept_acronym"] = self.departement.acronym
e.pop("departement", None)
e["sort_key"] = self.sort_key
return e
def inscriptions(self) -> list["FormSemestreInscription"]: