From c1f7bcdb92f6006f5ca9959c7b5f2b000e0b1665 Mon Sep 17 00:00:00 2001
From: Emmanuel Viennet <emmanuel.viennet@gmail.com>
Date: Sun, 3 Jul 2022 11:30:07 +0200
Subject: [PATCH] =?UTF-8?q?Cl=C3=A9=20tri=20=C3=A9tudiants:=20laisse=20esp?=
 =?UTF-8?q?aces=20internes?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/models/etudiants.py   | 6 +++---
 app/scodoc/sco_edit_ue.py | 2 +-
 app/scodoc/sco_utils.py   | 8 +++++---
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/app/models/etudiants.py b/app/models/etudiants.py
index 359ca35e5..30333a6b1 100644
--- a/app/models/etudiants.py
+++ b/app/models/etudiants.py
@@ -136,9 +136,9 @@ class Identite(db.Model):
         "clé pour tris par ordre alphabétique"
         return (
             scu.sanitize_string(
-                scu.suppress_accents(self.nom_usuel or self.nom or "").lower()
-            ),
-            scu.sanitize_string(scu.suppress_accents(self.prenom or "").lower()),
+                self.nom_usuel or self.nom or "", remove_spaces=False
+            ).lower(),
+            scu.sanitize_string(self.prenom or "", remove_spaces=False).lower(),
         )
 
     def get_first_email(self, field="email") -> str:
diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py
index 677c1ae49..def072c3c 100644
--- a/app/scodoc/sco_edit_ue.py
+++ b/app/scodoc/sco_edit_ue.py
@@ -451,7 +451,7 @@ def ue_edit(ue_id=None, create=False, formation_id=None, default_semestre_idx=No
             <ul>"""
             for m in ue.modules:
                 modules_div += f"""<li><a class="stdlink" href="{url_for(
-                    "notes.module_edit",scodoc_dept=g.scodoc_dept, module_id=m.id)}">{m.code} {m.titre}</a></li>"""
+                    "notes.module_edit",scodoc_dept=g.scodoc_dept, module_id=m.id)}">{m.code} {m.titre or "sans titre"}</a></li>"""
             modules_div += """</ul></div>"""
         else:
             modules_div = ""
diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py
index 88dca7fde..31de4bb22 100644
--- a/app/scodoc/sco_utils.py
+++ b/app/scodoc/sco_utils.py
@@ -588,7 +588,7 @@ def purge_chars(s, allowed_chars=""):
     return s.translate(PurgeChars(allowed_chars=allowed_chars))
 
 
-def sanitize_string(s):
+def sanitize_string(s, remove_spaces=True):
     """s is an ordinary string, encoding given by SCO_ENCODING"
     suppress accents and chars interpreted in XML
     Irreversible (not a quote)
@@ -596,8 +596,10 @@ def sanitize_string(s):
     For ids and some filenames
     """
     # Table suppressing some chars:
-    trans = str.maketrans("", "", "'`\"<>!&\\ ")
-    return suppress_accents(s.translate(trans)).replace(" ", "_").replace("\t", "_")
+    to_del = "'`\"<>!&\\ " if remove_spaces else "'`\"<>!&"
+    trans = str.maketrans("", "", to_del)
+
+    return suppress_accents(s.translate(trans)).replace("\t", "_")
 
 
 _BAD_FILENAME_CHARS = str.maketrans("", "", ":/\\&[]*?'")
-- 
GitLab