From 42f0cb8e7600c2752e63c734d48cac54eac13fe3 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 30 Aug 2022 19:13:21 +0200 Subject: [PATCH] Modification de /formsemestre//etudiants[/long] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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". --- app/api/formsemestres.py | 35 ++++++++++++++++++++++++++++------- app/models/etudiants.py | 4 +++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/api/formsemestres.py b/app/api/formsemestres.py index 32e2de5a9..9c8d99ea0 100644 --- a/app/api/formsemestres.py +++ b/app/api/formsemestres.py @@ -253,24 +253,42 @@ def formsemestre_programme(formsemestre_id: int): @bp.route( "/formsemestre//etudiants", - defaults={"with_query": False}, + defaults={"with_query": False, "long": False}, +) +@bp.route( + "/formsemestre//etudiants/long", + defaults={"with_query": False, "long": True}, ) @bp.route( "/formsemestre//etudiants/query", - defaults={"with_query": True}, + defaults={"with_query": True, "long": False}, +) +@bp.route( + "/formsemestre//etudiants/long/query", + defaults={"with_query": True, "long": True}, ) @api_web_bp.route( "/formsemestre//etudiants", - defaults={"with_query": False}, + defaults={"with_query": False, "long": False}, +) +@api_web_bp.route( + "/formsemestre//etudiants/long", + defaults={"with_query": False, "long": True}, ) @api_web_bp.route( "/formsemestre//etudiants/query", - defaults={"with_query": True}, + defaults={"with_query": True, "long": False}, +) +@api_web_bp.route( + "/formsemestre//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//etat_evals") diff --git a/app/models/etudiants.py b/app/models/etudiants.py index 987f640fb..1361fee2e 100644 --- a/app/models/etudiants.py +++ b/app/models/etudiants.py @@ -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"]: