diff --git a/app/tables/list_etuds.py b/app/tables/list_etuds.py index b520e50d2..3a90236cf 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 000000000..eab573e6d --- /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 958d7b0a0..c15766cea 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 1522700f6..076fbb4c2 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"