Table etud courants + export xlsx, + code nip

This commit is contained in:
Emmanuel Viennet 2023-11-26 19:04:03 +01:00
parent 568c8681ba
commit dcea12f6fc
4 changed files with 41 additions and 18 deletions

View File

@ -6,8 +6,10 @@
"""Liste simple d'étudiants """Liste simple d'étudiants
""" """
import datetime
from app.models import FormSemestre, FormSemestreInscription, Identite from app.models import FormSemestre, FormSemestreInscription, Identite
from app.scodoc.sco_exceptions import ScoValueError
from app.tables import table_builder as tb from app.tables import table_builder as tb
@ -79,7 +81,6 @@ class RowEtud(tb.Row):
# formsemestre_id=res.formsemestre.id, # formsemestre_id=res.formsemestre.id,
# etudid=etud.id, # etudid=etud.id,
# ) # )
url_bulletin = None # pour extension future
self.add_cell("civilite_str", "Civ.", etud.civilite_str, "identite_detail") self.add_cell("civilite_str", "Civ.", etud.civilite_str, "identite_detail")
self.add_cell( self.add_cell(
"nom_disp", "nom_disp",
@ -91,19 +92,6 @@ class RowEtud(tb.Row):
target_attrs={"class": "etudinfo discretelink", "id": str(etud.id)}, target_attrs={"class": "etudinfo discretelink", "id": str(etud.id)},
) )
self.add_cell("prenom", "Prénom", etud.prenom, "identite_detail") 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]: def etuds_sorted_from_ids(etudids) -> list[Identite]:
@ -149,6 +137,7 @@ class RowEtudWithInfos(RowEtud):
""", """,
"identite_detail", "identite_detail",
) )
self.add_cell("code_nip", "NIP", self.etud.code_nip or "", "identite_detail")
super().add_etud_cols() super().add_etud_cols()
self.add_cell( self.add_cell(
"etat", "etat",
@ -180,6 +169,8 @@ class TableEtudWithInfos(TableEtud):
def table_etudiants_courants(formsemestres: list[FormSemestre]) -> TableEtud: def table_etudiants_courants(formsemestres: list[FormSemestre]) -> TableEtud:
"""Table des étudiants des formsemestres indiqués""" """Table des étudiants des formsemestres indiqués"""
if not formsemestres:
raise ScoValueError("Aucun semestre en cours")
table = TableEtudWithInfos(row_class=RowEtudWithInfos) table = TableEtudWithInfos(row_class=RowEtudWithInfos)
for formsemestre in formsemestres: for formsemestre in formsemestres:
table.add_formsemestre(formsemestre) table.add_formsemestre(formsemestre)

View File

@ -0,0 +1,20 @@
{% extends "sco_page.j2" %}
{% block styles %}
{{super()}}
{% endblock %}
{% block app_content %}
<div class="tab-content">
<h2>Étudiants des semestres courants</h2>
<a href="{{
url_for('scolar.export_etudiants_courants', scodoc_dept=g.scodoc_dept, fmt='xls')
}}">{{scu.ICON_XLS|safe}}</a>
{{ table.html() | safe }}
</div>
{% endblock %}

View File

@ -2077,14 +2077,26 @@ def check_group_apogee(group_id, etat=None, fix=False, fixmail=False):
@permission_required(Permission.ScoView) @permission_required(Permission.ScoView)
def export_etudiants_courants(): def export_etudiants_courants():
"""Table export de tous les étudiants des formsemestres en cours.""" """Table export de tous les étudiants des formsemestres en cours."""
fmt = request.args.get("fmt", "html")
departement = Departement.query.get(g.scodoc_dept_id) departement = Departement.query.get(g.scodoc_dept_id)
if not departement: if not departement:
raise ScoValueError("département invalide") raise ScoValueError("département invalide")
formsemestres = FormSemestre.get_dept_formsemestres_courants(departement) formsemestres = FormSemestre.get_dept_formsemestres_courants(departement)
table = list_etuds.table_etudiants_courants(formsemestres) table = list_etuds.table_etudiants_courants(formsemestres)
return render_template( if fmt.startswith("xls"):
"scolar/export_etudiants_courants.j2", sco=ScoData(), table=table 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"]) @bp.route("/form_students_import_excel", methods=["GET", "POST"])

View File

@ -1,7 +1,7 @@
# -*- mode: python -*- # -*- mode: python -*-
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
SCOVERSION = "9.6.62" SCOVERSION = "9.6.63"
SCONAME = "ScoDoc" SCONAME = "ScoDoc"