From 61f9dddeb60d4c4d4a523f000fa8ba1b8c6504ac Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 24 Mar 2024 14:34:55 +0100 Subject: [PATCH] =?UTF-8?q?Modif.=20cl=C3=A9=20trie=20=C3=A9tudiants=20et?= =?UTF-8?q?=20utilisation=20dans=20=C3=A9diteur=20partition.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/formsemestres.py | 32 +++++++++++++++++------- app/models/etudiants.py | 12 ++++----- app/scodoc/sco_etud.py | 12 ++++----- app/templates/scolar/partition_editor.j2 | 2 +- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/app/api/formsemestres.py b/app/api/formsemestres.py index 1c3ddac2d..664a663bf 100644 --- a/app/api/formsemestres.py +++ b/app/api/formsemestres.py @@ -38,7 +38,7 @@ from app.scodoc import sco_groups from app.scodoc.sco_permissions import Permission from app.scodoc.sco_utils import ModuleType import app.scodoc.sco_utils as scu -from app.tables.recap import TableRecap +from app.tables.recap import TableRecap, RowRecap @bp.route("/formsemestre/") @@ -543,16 +543,30 @@ def formsemestre_resultat(formsemestre_id: int): formsemestre: FormSemestre = query.first_or_404(formsemestre_id) app.set_sco_dept(formsemestre.departement.acronym) res: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) - table = TableRecap( - res, convert_values=convert_values, include_evaluations=False, mode_jury=False - ) - # Supprime les champs inutiles (mise en forme) - rows = table.to_list() - # Ajoute le groupe de chaque partition: + # Ajoute le groupe de chaque partition, etud_groups = sco_groups.get_formsemestre_etuds_groups(formsemestre_id) - for row in rows: - row["partitions"] = etud_groups.get(row["etudid"], {}) + class RowRecapAPI(RowRecap): + """Pour table avec partitions et sort_key""" + + def add_etud_cols(self): + """Ajoute colonnes étudiant: codes, noms""" + super().add_etud_cols() + self.add_cell("partitions", "partitions", etud_groups.get(self.etud.id, {})) + self.add_cell("sort_key", "sort_key", self.etud.sort_key) + + table = TableRecap( + res, + convert_values=convert_values, + include_evaluations=False, + mode_jury=False, + row_class=RowRecapAPI, + ) + + rows = table.to_list() + + # for row in rows: + # row["partitions"] = etud_groups.get(row["etudid"], {}) return rows diff --git a/app/models/etudiants.py b/app/models/etudiants.py index d818c8e9f..03e6093bb 100644 --- a/app/models/etudiants.py +++ b/app/models/etudiants.py @@ -334,16 +334,14 @@ class Identite(models.ScoDocModel): return f"{(self.nom_usuel or self.nom or '?').upper()} {(self.prenom or '')[:2].capitalize()}." @cached_property - def sort_key(self) -> tuple: + def sort_key(self) -> str: "clé pour tris par ordre alphabétique" # Note: scodoc7 utilisait sco_etud.etud_sort_key, à mettre à jour # si on modifie cette méthode. - return ( - scu.sanitize_string( - self.nom_usuel or self.nom or "", remove_spaces=False - ).lower(), - scu.sanitize_string(self.prenom or "", remove_spaces=False).lower(), - ) + return scu.sanitize_string( + (self.nom_usuel or self.nom or "") + ";" + (self.prenom or ""), + remove_spaces=False, + ).lower() def get_first_email(self, field="email") -> str: "Le mail associé à la première adresse de l'étudiant, ou None" diff --git a/app/scodoc/sco_etud.py b/app/scodoc/sco_etud.py index 4cfaf5625..5ad690687 100644 --- a/app/scodoc/sco_etud.py +++ b/app/scodoc/sco_etud.py @@ -122,16 +122,14 @@ def format_pays(s): return "" -def etud_sort_key(etud: dict) -> tuple: +def etud_sort_key(etud: dict) -> str: """Clé de tri pour les étudiants représentés par des dict (anciens codes). Equivalent moderne: identite.sort_key """ - return ( - scu.sanitize_string( - etud.get("nom_usuel") or etud["nom"] or "", remove_spaces=False - ).lower(), - scu.sanitize_string(etud["prenom"] or "", remove_spaces=False).lower(), - ) + return scu.sanitize_string( + (etud.get("nom_usuel") or etud["nom"] or "") + ";" + (etud["prenom"] or ""), + remove_spaces=False, + ).lower() _identiteEditor = ndb.EditableTable( diff --git a/app/templates/scolar/partition_editor.j2 b/app/templates/scolar/partition_editor.j2 index 6d5bcf72e..4c5a44144 100644 --- a/app/templates/scolar/partition_editor.j2 +++ b/app/templates/scolar/partition_editor.j2 @@ -86,7 +86,7 @@ span.calendarEdit { let etudiants = await fetchData("/ScoDoc/{{formsemestre.departement.acronym}}/api/formsemestre/" + formsemestre_id + "/resultats"); etudiants.sort((a, b) => { - return a.nom_short.localeCompare(b.nom_short) + return a.sort_key.localeCompare(b.sort_key) }) processDatas(partitions, etudiants);