From d828be6be79d328c51937c670ac0f64e83526b0a Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 2 Sep 2022 22:00:34 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20#24=20(tri=20tables=20=C3=A9tudiants)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_etud.py | 12 ++++++++++++ app/scodoc/sco_groups.py | 4 +++- app/scodoc/sco_groups_view.py | 11 ++++++----- app/scodoc/sco_liste_notes.py | 9 +++++---- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/scodoc/sco_etud.py b/app/scodoc/sco_etud.py index 70f226b5..b3095c5b 100644 --- a/app/scodoc/sco_etud.py +++ b/app/scodoc/sco_etud.py @@ -205,6 +205,18 @@ def pivot_year(y): return y +def etud_sort_key(etud: dict) -> tuple: + """Clé de tri pour les étudiants représentés par des dict (anciens codes). + Equivalent moderne: identite.sort_key + """ + return ( + scu.sanitize_string( + etud["nom_usuel"] or etud["nom"] or "", remove_spaces=False + ).lower(), + scu.sanitize_string(etud["prenom"] or "", remove_spaces=False).lower(), + ) + + _identiteEditor = ndb.EditableTable( "identite", "etudid", diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index a17d0878..c68e4342 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -60,6 +60,7 @@ from app.scodoc import sco_cache from app.scodoc import sco_codes_parcours from app.scodoc import sco_cursus from app.scodoc import sco_etud +from app.scodoc.sco_etud import etud_sort_key from app.scodoc import sco_permissions_check from app.scodoc import sco_xml from app.scodoc.sco_exceptions import ScoException, AccessDenied, ScoValueError @@ -283,7 +284,8 @@ def get_group_members(group_id, etat=None): for etud in r: sco_etud.format_etud_ident(etud) - r.sort(key=operator.itemgetter("nom_disp", "prenom")) # tri selon nom_usuel ou nom + # tri selon nom_usuel ou nom, sans accents + r.sort(key=etud_sort_key) if scu.CONFIG.ALLOW_NULL_PRENOM: for x in r: diff --git a/app/scodoc/sco_groups_view.py b/app/scodoc/sco_groups_view.py index 9588abd4..eaf9ff0f 100644 --- a/app/scodoc/sco_groups_view.py +++ b/app/scodoc/sco_groups_view.py @@ -53,6 +53,7 @@ from app.scodoc import sco_cursus from app.scodoc import sco_portal_apogee from app.scodoc import sco_preferences from app.scodoc import sco_etud +from app.scodoc.sco_etud import etud_sort_key from app.scodoc.gen_tables import GenTable from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_permissions import Permission @@ -398,12 +399,11 @@ class DisplayedGroupsInfos(object): self.partitions.append(partition) def sortuniq(self): - "Trie les étudiants (de plusieurs groupes) et elimine les doublons" + "Trie les étudiants (de plusieurs groupes) et élimine les doublons" if (len(self.group_ids) <= 1) or len(self.members) <= 1: return # on suppose que les etudiants d'un groupe sont deja triés - self.members.sort( - key=operator.itemgetter("nom_disp", "prenom") - ) # tri selon nom_usuel ou nom + # tri selon nom_usuel ou nom, sans accents + self.members.sort(key=etud_sort_key) to_remove = [] T = self.members for i in range(len(T) - 1, 0, -1): @@ -422,7 +422,7 @@ class DisplayedGroupsInfos(object): # Ancien ZScolar.group_list renommé ici en group_table def groups_table( - groups_infos=None, # instance of DisplayedGroupsInfos + groups_infos: DisplayedGroupsInfos = None, with_codes=0, etat=None, format="html", @@ -520,6 +520,7 @@ def groups_table( "scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etud["etudid"] ) etud["_nom_disp_target"] = fiche_url + etud["_nom_disp_order"] = etud_sort_key(etud) etud["_prenom_target"] = fiche_url etud["_nom_disp_td_attrs"] = 'id="%s" class="etudinfo"' % (etud["etudid"]) diff --git a/app/scodoc/sco_liste_notes.py b/app/scodoc/sco_liste_notes.py index cee1e849..54d53e93 100644 --- a/app/scodoc/sco_liste_notes.py +++ b/app/scodoc/sco_liste_notes.py @@ -44,10 +44,10 @@ 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 import app.scodoc.notesdb as ndb from app.scodoc.TrivialFormulator import TrivialFormulator +from app.scodoc.sco_etud import etud_sort_key from app.scodoc import sco_evaluations from app.scodoc import sco_evaluation_db from app.scodoc import sco_formsemestre @@ -55,6 +55,7 @@ from app.scodoc import sco_groups from app.scodoc import sco_moduleimpl from app.scodoc import sco_preferences from app.scodoc import sco_users +import app.scodoc.sco_utils as scu import sco_version from app.scodoc.gen_tables import GenTable from app.scodoc.htmlutils import histogram_notes @@ -352,6 +353,7 @@ def _make_table_notes( ), "_nomprenom_td_attrs": f"""id="{etudid}" class="etudinfo" data-sort="{etud.sort_key}" """, "prenom": etud.prenom.lower().capitalize(), + "nom_usuel": etud.nom_usuel, "nomprenom": etud.nomprenom, "group": grc, "_group_td_attrs": 'class="group"', @@ -420,9 +422,8 @@ def _make_table_notes( if anonymous_listing: rows.sort(key=lambda x: x["code"] or "") else: - rows.sort( - key=lambda x: (x["nom"] or "", x["prenom"] or "") - ) # sort by nom, prenom + # sort by nom, prenom, sans accents + rows.sort(key=etud_sort_key) # Si module, ajoute la (les) "moyenne(s) du module: if mode == "module":