From 0c3216e43287350bd63e21b65c61a5964d7b7dbf Mon Sep 17 00:00:00 2001
From: Emmanuel Viennet <emmanuel.viennet@gmail.com>
Date: Mon, 26 Aug 2024 08:34:15 +0200
Subject: [PATCH] =?UTF-8?q?Am=C3=A9liore=20evaluation=5Flistenotes=20+=20c?=
 =?UTF-8?q?osmetic?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/scodoc/sco_liste_notes.py            | 85 ++++++++++++++++--------
 app/static/css/scodoc97.css              |  3 +-
 app/templates/scolar/partition_editor.j2 |  2 +-
 app/views/notes.py                       | 27 ++++----
 4 files changed, 76 insertions(+), 41 deletions(-)

diff --git a/app/scodoc/sco_liste_notes.py b/app/scodoc/sco_liste_notes.py
index c71238ee..fda6e0d8 100644
--- a/app/scodoc/sco_liste_notes.py
+++ b/app/scodoc/sco_liste_notes.py
@@ -63,12 +63,13 @@ def do_evaluation_listenotes(
     """
     Affichage des notes d'une évaluation (si evaluation_id)
     ou de toutes les évaluations d'un module (si moduleimpl_id)
+
     """
     mode = None
     evaluations: list[Evaluation] = []
     if moduleimpl_id is not None:
         mode = "module"
-        modimpl = ModuleImpl.query.get_or_404(moduleimpl_id)
+        modimpl = ModuleImpl.get_modimpl(moduleimpl_id)
         evaluations = modimpl.evaluations.all()
     elif evaluation_id is not None:
         mode = "eval"
@@ -76,11 +77,13 @@ def do_evaluation_listenotes(
     else:
         raise ValueError("missing argument: evaluation or module")
     if not evaluations:
+        if fmt == "json":
+            return [], ""
         return "<p>Aucune évaluation !</p>", "ScoDoc"
     evaluation = evaluations[0]
     modimpl = evaluation.moduleimpl  # il y a au moins une evaluation
 
-    # description de l'evaluation
+    # description de l'évaluation
     if evaluation_id is not None:
         H = [sco_evaluations.evaluation_describe(evaluation_id=evaluation_id)]
         page_title = f"Notes {evaluation.description or modimpl.module.code}"
@@ -172,6 +175,17 @@ def do_evaluation_listenotes(
                 "template": "%(elem)s &nbsp;&nbsp;",
             },
         ),
+        (
+            "split_groups",
+            {
+                "input_type": "checkbox",
+                "title": "",
+                "allowed_values": ("yes",),
+                "labels": ("détailler les groupes",),
+                "attributes": ('onclick="document.tf.submit();"',),
+                "template": "%(elem)s &nbsp;&nbsp;",
+            },
+        ),
         (
             "with_emails",
             {
@@ -213,6 +227,7 @@ def do_evaluation_listenotes(
         anonymous_listing = tf[2]["anonymous_listing"]
         note_sur_20 = tf[2]["note_sur_20"]
         hide_groups = tf[2]["hide_groups"]
+        split_groups = tf[2]["split_groups"]
         with_emails = tf[2]["with_emails"]
         group_ids = [x for x in tf[2]["group_ids"] if x != ""]
         return (
@@ -224,6 +239,7 @@ def do_evaluation_listenotes(
                 anonymous_listing=anonymous_listing,
                 group_ids=group_ids,
                 hide_groups=hide_groups,
+                split_groups=split_groups,
                 with_emails=with_emails,
                 mode=mode,
             ),
@@ -238,6 +254,7 @@ def _make_table_notes(
     note_sur_20=False,
     anonymous_listing=False,
     hide_groups=False,
+    split_groups=False,
     with_emails=False,
     group_ids: list[int] | None = None,
     mode="module",  # "eval" or "module"
@@ -284,7 +301,13 @@ def _make_table_notes(
             columns_ids = ["etudid", "nom", "prenom"]
         else:
             columns_ids = ["nomprenom"]
-    if not hide_groups and fmt not in {"xml", "json"}:
+    partitions = []
+    if split_groups:
+        partitions = formsemestre.get_partitions_list(
+            with_default=False, only_listed=True
+        )
+        columns_ids += [f"partition_{p.id}" for p in partitions]
+    elif not hide_groups and fmt not in {"xml", "json"}:
         # n'indique pas les groupes en xml et json car notation "humaine" ici
         columns_ids.append("group")
 
@@ -299,6 +322,7 @@ def _make_table_notes(
         "emailperso": "e-mail perso",
         "signatures": "Signatures",
     }
+    titles.update({f"partition_{p.id}": p.partition_name or "" for p in partitions})
     rows = []
 
     class KeyManager(dict):
@@ -339,41 +363,46 @@ def _make_table_notes(
         if etat == scu.INSCRIT:  # si inscrit, indique groupe
             groups = sco_groups.get_etud_groups(etudid, formsemestre.id)
             grc = sco_groups.listgroups_abbrev(groups)
+            groups_cols = {
+                f"partition_{p.id}": p.get_etud_group(etudid).group_name or ""
+                for p in partitions
+            }
         else:
             if etat == scu.DEMISSION:
                 grc = "DEM"  # attention: ce code est re-ecrit plus bas, ne pas le changer (?)
                 css_row_class = "etuddem"
             else:
                 grc = etat
+            groups_cols = {f"partition_{p.id}": etat for p in partitions}
 
         code = getattr(etud, anonymous_lst_key)
         if not code:  # laisser le code vide n'aurait aucun sens, prenons l'etudid
             code = etudid
 
-        rows.append(
-            {
-                "code": str(code),  # INE, NIP ou etudid
-                "_code_td_attrs": 'style="padding-left: 1em; padding-right: 2em;"',
-                "etudid": etudid,
-                "nom": etud.nom.upper(),
-                "_nomprenom_target": url_for(
-                    "notes.formsemestre_bulletinetud",
-                    scodoc_dept=g.scodoc_dept,
-                    formsemestre_id=formsemestre.id,
-                    etudid=etudid,
-                ),
-                "_nomprenom_td_attrs": f"""id="{etudid}" class="etudinfo" data-sort="{
+        row = {
+            "code": str(code),  # INE, NIP ou etudid
+            "_code_td_attrs": 'style="padding-left: 1em; padding-right: 2em;"',
+            "etudid": etudid,
+            "nom": etud.nom.upper(),
+            "_nomprenom_target": url_for(
+                "notes.formsemestre_bulletinetud",
+                scodoc_dept=g.scodoc_dept,
+                formsemestre_id=formsemestre.id,
+                etudid=etudid,
+            ),
+            "_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"',
-                "email": etud.get_first_email(),
-                "emailperso": etud.get_first_email("emailperso"),
-                "_css_row_class": css_row_class or "",
-            }
-        )
+            "prenom": etud.prenom.lower().capitalize(),
+            "nom_usuel": etud.nom_usuel,
+            "nomprenom": etud.nomprenom,
+            "group": grc,
+            "_group_td_attrs": 'class="group"',
+            "email": etud.get_first_email(),
+            "emailperso": etud.get_first_email("emailperso"),
+            "_css_row_class": css_row_class or "",
+        }
+        row.update(groups_cols)
+        rows.append(row)
 
     # Lignes en tête:
     row_coefs = {
@@ -517,6 +546,8 @@ def _make_table_notes(
         gl = "&anonymous_listing%3Alist=yes" + gl
     if hide_groups:
         gl = "&hide_groups%3Alist=yes" + gl
+    if split_groups:
+        gl = "&split_groups%3Alist=yes" + gl
     if with_emails:
         gl = "&with_emails%3Alist=yes" + gl
     if len(evaluations) == 1:
@@ -573,7 +604,7 @@ def _make_table_notes(
         title = f"Notes {module.type_name()} {module.code} {module.titre}"
         title += f""" semestre {formsemestre.titre_mois()}"""
         if gr_title and gr_title != "tous":
-            title += " {gr_title}"
+            title += f" {gr_title}"
         caption = title
         html_next_section = ""
         if fmt == "pdf" or fmt == "bordereau":
diff --git a/app/static/css/scodoc97.css b/app/static/css/scodoc97.css
index 43dd369f..ed06fb6d 100644
--- a/app/static/css/scodoc97.css
+++ b/app/static/css/scodoc97.css
@@ -446,7 +446,8 @@ textarea {
  */
 @media (min-width: 769px) {
     .form-group input[type="submit"] {
-        width: 192px;
+        min-width: 192px;
+        width: auto;
     }
 }
 
diff --git a/app/templates/scolar/partition_editor.j2 b/app/templates/scolar/partition_editor.j2
index 68afc2a3..70ad81bb 100644
--- a/app/templates/scolar/partition_editor.j2
+++ b/app/templates/scolar/partition_editor.j2
@@ -36,7 +36,7 @@
 			<label class="edition">
 				<input type="checkbox" autocomplete="off" id="inputModif"
 					{% if edit_partition %}checked{% endif %}>
-				Modifier les partitions et groupes
+				Créer ou modifier partitions et groupes
 			</label>
 			<div class="filtres"></div>
 			<div style="display: flex; justify-content: space-between;">
diff --git a/app/views/notes.py b/app/views/notes.py
index 3ba9ef0a..c153e75e 100644
--- a/app/views/notes.py
+++ b/app/views/notes.py
@@ -1755,26 +1755,29 @@ def evaluation_create(moduleimpl_id):
     )
 
 
-@bp.route("/evaluation_listenotes", methods=["GET", "POST"])  # API ScoDoc 7 compat
+@bp.route("/evaluation_listenotes")
 @scodoc
 @permission_required_compat_scodoc7(Permission.ScoView)
-@scodoc7func
 def evaluation_listenotes():
     """Affichage des notes d'une évaluation.
-    Si evaluation_id non spécifié, toutes les notes des évaluations de ce modimpl.
+    Args:
+    - evaluation_id (une seule éval)
+    - ou moduleimpl_id (toutes les évals du module)
+    - group_ids: groupes à lister
+    - fmt : html, xls, pdf, json
     """
-    evaluation_id = None
-    moduleimpl_id = None
-    vals = scu.get_request_args()
+    # Arguments
+    evaluation_id = request.args.get("evaluation_id")
+    moduleimpl_id = request.args.get("moduleimpl_id")
     try:
-        if "evaluation_id" in vals:
-            evaluation_id = int(vals["evaluation_id"])
-        if "moduleimpl_id" in vals and vals["moduleimpl_id"]:
-            moduleimpl_id = int(vals["moduleimpl_id"])
+        if evaluation_id is not None:
+            evaluation_id = int(evaluation_id)
+        if moduleimpl_id is not None:
+            moduleimpl_id = int(moduleimpl_id)
     except ValueError as exc:
         raise ScoValueError("evaluation_listenotes: id invalides !") from exc
-
-    fmt = vals.get("fmt", "html")
+    fmt = request.args.get("fmt", "html")
+    #
     content, page_title = sco_liste_notes.do_evaluation_listenotes(
         evaluation_id=evaluation_id, moduleimpl_id=moduleimpl_id, fmt=fmt
     )
-- 
GitLab