From dcea12f6fc868de2297e1db1e8902968c74591aa Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 26 Nov 2023 19:04:03 +0100 Subject: [PATCH] Table etud courants + export xlsx, + code nip --- app/tables/list_etuds.py | 19 +++++------------- .../scolar/export_etudiants_courants.j2 | 20 +++++++++++++++++++ app/views/scolar.py | 18 ++++++++++++++--- sco_version.py | 2 +- 4 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 app/templates/scolar/export_etudiants_courants.j2 diff --git a/app/tables/list_etuds.py b/app/tables/list_etuds.py index b520e50d..3a90236c 100644 --- a/app/tables/list_etuds.py +++ b/app/tables/list_etuds.py @@ -6,8 +6,10 @@ """Liste simple d'étudiants """ +import datetime from app.models import FormSemestre, FormSemestreInscription, Identite +from app.scodoc.sco_exceptions import ScoValueError from app.tables import table_builder as tb @@ -79,7 +81,6 @@ class RowEtud(tb.Row): # formsemestre_id=res.formsemestre.id, # etudid=etud.id, # ) - url_bulletin = None # pour extension future self.add_cell("civilite_str", "Civ.", etud.civilite_str, "identite_detail") self.add_cell( "nom_disp", @@ -91,19 +92,6 @@ class RowEtud(tb.Row): target_attrs={"class": "etudinfo discretelink", "id": str(etud.id)}, ) self.add_cell("prenom", "Prénom", etud.prenom, "identite_detail") - # self.add_cell( - # "nom_short", - # "Nom", - # etud.nom_short, - # "identite_court", - # data={ - # "order": etud.sort_key, - # "etudid": etud.id, - # "nomprenom": etud.nomprenom, - # }, - # target=url_bulletin, - # target_attrs={"class": "etudinfo", "id": str(etud.id)}, - # ) def etuds_sorted_from_ids(etudids) -> list[Identite]: @@ -149,6 +137,7 @@ class RowEtudWithInfos(RowEtud): """, "identite_detail", ) + self.add_cell("code_nip", "NIP", self.etud.code_nip or "", "identite_detail") super().add_etud_cols() self.add_cell( "etat", @@ -180,6 +169,8 @@ class TableEtudWithInfos(TableEtud): def table_etudiants_courants(formsemestres: list[FormSemestre]) -> TableEtud: """Table des étudiants des formsemestres indiqués""" + if not formsemestres: + raise ScoValueError("Aucun semestre en cours") table = TableEtudWithInfos(row_class=RowEtudWithInfos) for formsemestre in formsemestres: table.add_formsemestre(formsemestre) diff --git a/app/templates/scolar/export_etudiants_courants.j2 b/app/templates/scolar/export_etudiants_courants.j2 new file mode 100644 index 00000000..eab573e6 --- /dev/null +++ b/app/templates/scolar/export_etudiants_courants.j2 @@ -0,0 +1,20 @@ +{% extends "sco_page.j2" %} + +{% block styles %} +{{super()}} +{% endblock %} + +{% block app_content %} + +
+

Étudiants des semestres courants

+ +{{scu.ICON_XLS|safe}} + + +{{ table.html() | safe }} + +
+{% endblock %} diff --git a/app/views/scolar.py b/app/views/scolar.py index 958d7b0a..c15766ce 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -2077,14 +2077,26 @@ def check_group_apogee(group_id, etat=None, fix=False, fixmail=False): @permission_required(Permission.ScoView) def export_etudiants_courants(): """Table export de tous les étudiants des formsemestres en cours.""" + fmt = request.args.get("fmt", "html") departement = Departement.query.get(g.scodoc_dept_id) if not departement: raise ScoValueError("département invalide") formsemestres = FormSemestre.get_dept_formsemestres_courants(departement) table = list_etuds.table_etudiants_courants(formsemestres) - return render_template( - "scolar/export_etudiants_courants.j2", sco=ScoData(), table=table - ) + if fmt.startswith("xls"): + return scu.send_file( + table.excel(), + f"""{formsemestres[0].departement.acronym}-etudiants-{ + datetime.datetime.now().strftime("%Y-%m-%dT%Hh%M")}""", + scu.XLSX_SUFFIX, + mime=scu.XLSX_MIMETYPE, + ) + elif fmt == "html": + return render_template( + "scolar/export_etudiants_courants.j2", sco=ScoData(), table=table + ) + else: + raise ScoValueError("invalid fmt value") @bp.route("/form_students_import_excel", methods=["GET", "POST"]) diff --git a/sco_version.py b/sco_version.py index 1522700f..076fbb4c 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.6.62" +SCOVERSION = "9.6.63" SCONAME = "ScoDoc"