From 83d538e2a27abd055669eea521ed2d1f67664caf Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 3 Apr 2022 23:26:13 +0200 Subject: [PATCH] Tri tables sans diacritiques. Closes #122 --- app/comp/res_common.py | 2 ++ app/models/etudiants.py | 5 ++++- app/scodoc/sco_liste_notes.py | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/comp/res_common.py b/app/comp/res_common.py index fbeba8bed..1f19fbfd9 100644 --- a/app/comp/res_common.py +++ b/app/comp/res_common.py @@ -469,10 +469,12 @@ class ResultatsSemestre(ResultatsCache): idx = add_cell( row, "nom_disp", "Nom", etud.nom_disp(), "identite_detail", idx ) + row["_nom_disp_order"] = etud.sort_key idx = add_cell(row, "prenom", "Prénom", etud.prenom, "identite_detail", idx) idx = add_cell( row, "nom_short", "Nom", etud.nom_short, "identite_court", idx ) + row["_nom_short_order"] = etud.sort_key row["_nom_short_target"] = url_for( "notes.formsemestre_bulletinetud", scodoc_dept=g.scodoc_dept, diff --git a/app/models/etudiants.py b/app/models/etudiants.py index b1a49e5c2..6c342482c 100644 --- a/app/models/etudiants.py +++ b/app/models/etudiants.py @@ -131,7 +131,10 @@ class Identite(db.Model): @cached_property def sort_key(self) -> tuple: "clé pour tris par ordre alphabétique" - return (self.nom_usuel or self.nom).lower(), self.prenom.lower() + return ( + scu.suppress_accents(self.nom_usuel or self.nom or "").lower(), + scu.suppress_accents(self.prenom or "").lower(), + ) def get_first_email(self, field="email") -> str: "Le mail associé à la première adrese de l'étudiant, ou None" diff --git a/app/scodoc/sco_liste_notes.py b/app/scodoc/sco_liste_notes.py index 7a22ccbed..cedd390fb 100644 --- a/app/scodoc/sco_liste_notes.py +++ b/app/scodoc/sco_liste_notes.py @@ -41,6 +41,7 @@ from app.comp.moy_mod import ModuleImplResults from app.comp.res_compat import NotesTableCompat from app.comp.res_but import ResultatsSemestreBUT from app.models import FormSemestre +from app.models.etudiants import Identite from app.models.evaluations import Evaluation from app.models.moduleimpls import ModuleImpl import app.scodoc.sco_utils as scu @@ -53,7 +54,6 @@ from app.scodoc import sco_formsemestre from app.scodoc import sco_groups from app.scodoc import sco_moduleimpl from app.scodoc import sco_preferences -from app.scodoc import sco_etud from app.scodoc import sco_users import sco_version from app.scodoc.gen_tables import GenTable @@ -320,7 +320,9 @@ def _make_table_notes( for etudid, etat in etudid_etats: css_row_class = None # infos identite etudiant - etud = sco_etud.get_etud_info(etudid=etudid, filled=True)[0] + etud = Identite.query.get(etudid) + if etud is None: + continue if etat == "I": # si inscrit, indique groupe groups = sco_groups.get_etud_groups(etudid, modimpl_o["formsemestre_id"]) @@ -332,7 +334,7 @@ def _make_table_notes( else: grc = etat - code = etud.get(anonymous_lst_key) + code = getattr(etud, anonymous_lst_key) if not code: # laisser le code vide n'aurait aucun sens, prenons l'etudid code = etudid @@ -341,20 +343,20 @@ def _make_table_notes( "code": str(code), # INE, NIP ou etudid "_code_td_attrs": 'style="padding-left: 1em; padding-right: 2em;"', "etudid": etudid, - "nom": etud["nom"].upper(), + "nom": etud.nom.upper(), "_nomprenom_target": url_for( "notes.formsemestre_bulletinetud", scodoc_dept=g.scodoc_dept, formsemestre_id=modimpl_o["formsemestre_id"], etudid=etudid, ), - "_nomprenom_td_attrs": f"""id="{etudid}" class="etudinfo" data-sort="{etud.get('nom', '').upper()}" """, - "prenom": etud["prenom"].lower().capitalize(), - "nomprenom": etud["nomprenom"], + "_nomprenom_td_attrs": f"""id="{etudid}" class="etudinfo" data-sort="{etud.sort_key}" """, + "prenom": etud.prenom.lower().capitalize(), + "nomprenom": etud.nomprenom, "group": grc, "_group_td_attrs": 'class="group"', - "email": etud["email"], - "emailperso": etud["emailperso"], + "email": etud.get_first_email(), + "emailperso": etud.get_first_email("emailperso"), "_css_row_class": css_row_class or "", } )