From fb5cdc2624ab10952e1f8cd09ca2c52bb9922a41 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 20 Jul 2023 15:53:59 +0200 Subject: [PATCH] =?UTF-8?q?VisualisationAssiduitesGroupe:=20am=C3=A9liore?= =?UTF-8?q?=20table=20+=20export=20excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_groups_view.py | 11 +++++- app/tables/visu_assiduites.py | 26 +++++++++------ app/templates/assiduites/pages/visu_assi.j2 | 21 +++++++++--- app/views/assiduites.py | 37 +++++++++++---------- sco_version.py | 2 +- 5 files changed, 62 insertions(+), 35 deletions(-) diff --git a/app/scodoc/sco_groups_view.py b/app/scodoc/sco_groups_view.py index bfb7590211..8dbd20593b 100644 --- a/app/scodoc/sco_groups_view.py +++ b/app/scodoc/sco_groups_view.py @@ -33,7 +33,6 @@ import collections import datetime -import operator import urllib from urllib.parse import parse_qs import time @@ -42,6 +41,8 @@ import time from flask import url_for, g, request from flask_login import current_user +from app import db +from app.models import FormSemestre import app.scodoc.sco_utils as scu from app.scodoc import html_sco_header from app.scodoc import sco_abs @@ -65,6 +66,7 @@ JAVASCRIPTS = html_sco_header.BOOTSTRAP_MULTISELECT_JS + [ CSSSTYLES = html_sco_header.BOOTSTRAP_MULTISELECT_CSS + # view: def groups_view( group_ids=(), @@ -422,6 +424,13 @@ class DisplayedGroupsInfos(object): H.append(f'') return "\n".join(H) + def get_formsemestre(self) -> FormSemestre: + return ( + db.session.get(FormSemestre, self.formsemestre_id) + if self.formsemestre_id + else None + ) + # Ancien ZScolar.group_list renommé ici en group_table def groups_table( diff --git a/app/tables/visu_assiduites.py b/app/tables/visu_assiduites.py index 3c8304b9ef..9522341b55 100644 --- a/app/tables/visu_assiduites.py +++ b/app/tables/visu_assiduites.py @@ -8,7 +8,7 @@ """ from flask import g, url_for -from app.models import Identite, Assiduite, Justificatif +from app.models import Identite, Justificatif from app.tables import table_builder as tb import app.scodoc.sco_assiduites as scass from app.scodoc import sco_preferences @@ -65,31 +65,35 @@ class RowAssi(tb.Row): } ) - bilan_etud = f"{url_for('assiduites.bilan_etud', scodoc_dept=g.scodoc_dept)}?etudid={etud.id}" + bilan_etud = url_for( + "assiduites.bilan_etud", scodoc_dept=g.scodoc_dept, etudid=etud.id + ) self.add_cell( "nom_disp", "Nom", etud.nom_disp(), - "identite_detail", + "etudinfo", + attrs={"id": str(etud.id)}, data={"order": etud.sort_key}, target=bilan_etud, - target_attrs={"class": "discretelink", "id": str(etud.id)}, + target_attrs={"class": "discretelink"}, ) self.add_cell( "prenom", "Prénom", - etud.prenom, - "identite_detail", + etud.prenom_str, + "etudinfo", + attrs={"id": str(etud.id)}, data={"order": etud.sort_key}, target=bilan_etud, - target_attrs={"class": "discretelink", "id": str(etud.id)}, + target_attrs={"class": "discretelink"}, ) stats = self._get_etud_stats(etud) for key, value in stats.items(): self.add_cell(key, value[0], f"{value[1] - value[2]}", "assi_stats") self.add_cell( key + "_justi", - value[0] + " Justifiée(s)", + value[0] + " Justifiées", f"{value[2]}", "assi_stats", ) @@ -102,9 +106,9 @@ class RowAssi(tb.Row): def _get_etud_stats(self, etud: Identite) -> dict[str, list[str, float, float]]: retour: dict[str, tuple[str, float, float]] = { - "present": ["Présence(s)", 0.0, 0.0], - "retard": ["Retard(s)", 0.0, 0.0], - "absent": ["Absence(s)", 0.0, 0.0], + "present": ["Présences", 0.0, 0.0], + "retard": ["Retards", 0.0, 0.0], + "absent": ["Absences", 0.0, 0.0], } assi_metric = { diff --git a/app/templates/assiduites/pages/visu_assi.j2 b/app/templates/assiduites/pages/visu_assi.j2 index 250c884e7a..882eadb28d 100644 --- a/app/templates/assiduites/pages/visu_assi.j2 +++ b/app/templates/assiduites/pages/visu_assi.j2 @@ -1,11 +1,22 @@ +{% extends "sco_page.j2" %} + +{% block scripts %} + {{ super() }} + +{% endblock %} + +{% block app_content %} +

Visualisation de l'assiduité {{gr_tit|safe}}

- - - + + + {{scu.ICON_XLS|safe}}
{{tableau | safe}} @@ -26,4 +37,6 @@ document.querySelector('#stats_date_fin').value = date_fin; }) - \ No newline at end of file + + +{% endblock %} diff --git a/app/views/assiduites.py b/app/views/assiduites.py index d467879ddb..df25d3c009 100644 --- a/app/views/assiduites.py +++ b/app/views/assiduites.py @@ -649,6 +649,7 @@ def visu_assi_group(): "debut": request.args.get("date_debut"), "fin": request.args.get("date_fin"), } + fmt = request.args.get("format", "html") group_ids: list[int] = request.args.get("group_ids", None) etudiants: list[dict] = [] @@ -662,14 +663,16 @@ def visu_assi_group(): groups_infos = sco_groups_view.DisplayedGroupsInfos(group_ids) etuds = etuds_sorted_from_ids([m["etudid"] for m in groups_infos.members]) - - header: str = html_sco_header.sco_header( - page_title="Visualisation des assiduités", - init_qtip=True, - ) - table: TableAssi = TableAssi(etuds=etuds, dates=list(dates.values())) + if fmt.startswith("xls"): + return scu.send_file( + table.excel(), + filename=f"assiduite-{groups_infos.groups_filename}", + mime=scu.XLSX_MIMETYPE, + suffix=scu.XLSX_SUFFIX, + ) + if groups_infos.tous_les_etuds_du_sem: gr_tit = "en" else: @@ -681,18 +684,16 @@ def visu_assi_group(): grp + ' ' + groups_infos.groups_titles + "" ) - return HTMLBuilder( - header, - render_template( - "assiduites/pages/visu_assi.j2", - tableau=table.html(), - gr_tit=gr_tit, - date_debut=dates["debut"], - date_fin=dates["fin"], - group_ids=request.args.get("group_ids", None), - ), - html_sco_header.sco_footer(), - ).build() + return render_template( + "assiduites/pages/visu_assi.j2", + tableau=table.html(), + gr_tit=gr_tit, + date_debut=dates["debut"], + date_fin=dates["fin"], + group_ids=request.args.get("group_ids", None), + sco=ScoData(formsemestre=groups_infos.get_formsemestre()), + title=f"Assiduité {grp} {groups_infos.groups_titles}", + ) @bp.route("/SignalAssiduiteDifferee") diff --git a/sco_version.py b/sco_version.py index f07249a989..329458b3e9 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.6.2" +SCOVERSION = "9.6.3" SCONAME = "ScoDoc"