ScoDoc/app/views/groups.py

87 lines
2.7 KiB
Python
Raw Normal View History

2024-07-12 16:40:46 +02:00
"""
Nouvelles vues pour les groupes
(aux normes ScoDoc9)
"""
from flask import render_template, request
from app import log
2024-07-12 16:40:46 +02:00
from app.decorators import (
scodoc,
permission_required,
)
from app.forms.scolar import groups_form
from app.models import FormSemestre
2024-07-12 16:40:46 +02:00
from app.scodoc.sco_excel import excel_feuille_listeappel
from app.scodoc.sco_exceptions import ScoValueError
2024-07-12 16:40:46 +02:00
from app.scodoc.sco_groups_view import DisplayedGroupsInfos, menu_groups_choice
from app.scodoc.sco_permissions import Permission
from app.scodoc import sco_utils as scu
from app.views import ScoData
from app.views import scolar_bp as bp
@bp.route("/formulaire_feuille_appel/<int:formsemestre_id>", methods=["GET", "POST"])
2024-07-12 16:40:46 +02:00
@scodoc
@permission_required(Permission.ScoView)
def formulaire_feuille_appel(formsemestre_id: int):
2024-07-12 16:40:46 +02:00
"""Formulaire de feuille d'appel
GET Affiche le formulaire de remplissage de la feuille d'appel
POST (soumission) retourne la feuille d'appel correspondante
2024-07-12 16:40:46 +02:00
QUERY
-----
group_ids:<list:<int:group_id>>
"""
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
if request.method == "GET":
group_ids: list[int] = request.args.getlist("group_ids")
data = {"group_ids": group_ids}
else:
2024-08-25 08:05:40 +02:00
group_ids_list = request.form.getlist("group_ids")
try:
2024-08-25 08:05:40 +02:00
group_ids = [int(gid) for gid in group_ids_list if gid]
except ValueError as exc:
2024-08-25 08:05:40 +02:00
log(f"formulaire_feuille_appel: group_ids invalide: {group_ids_list[:100]}")
raise ScoValueError("groupes invalides") from exc
data = {}
form = groups_form.FeuilleAppelPreForm(request.form, data=data)
2024-07-12 16:40:46 +02:00
groups_infos = DisplayedGroupsInfos(
group_ids,
formsemestre_id=formsemestre_id,
select_all_when_unspecified=True,
)
if form.validate_on_submit():
2024-07-12 16:40:46 +02:00
edt_params: dict = {
"date": form.date.data or "",
"heure": form.heure.data or "",
"discipline": form.discipline.data or "",
"ens": form.ens.data or "",
}
xls = excel_feuille_listeappel(
groups_infos.formsemestre,
groups_infos.groups_titles,
groups_infos.members,
partitions=groups_infos.partitions,
edt_params=edt_params,
)
filename = f"liste_{groups_infos.groups_filename}"
return scu.send_file(xls, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE)
return render_template(
"scolar/formulaire_feuille_appel.j2",
sco_data=ScoData(formsemestre=formsemestre),
form=form,
group_name=groups_infos.groups_titles,
2024-08-25 08:05:40 +02:00
grp=menu_groups_choice(groups_infos),
formsemestre_id=formsemestre_id,
2024-07-12 16:40:46 +02:00
)