2024-07-12 16:40:46 +02:00
|
|
|
"""
|
|
|
|
Nouvelles vues pour les groupes
|
|
|
|
(aux normes ScoDoc9)
|
|
|
|
"""
|
|
|
|
|
|
|
|
from flask import render_template, request
|
|
|
|
|
2024-08-23 17:59:55 +02:00
|
|
|
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
|
2024-08-23 17:59:55 +02:00
|
|
|
from app.models import FormSemestre
|
2024-07-12 16:40:46 +02:00
|
|
|
from app.scodoc.sco_excel import excel_feuille_listeappel
|
2024-08-23 17:59:55 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2024-08-23 17:59:55 +02:00
|
|
|
@bp.route("/formulaire_feuille_appel/<int:formsemestre_id>", methods=["GET", "POST"])
|
2024-07-12 16:40:46 +02:00
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2024-08-23 17:59:55 +02:00
|
|
|
def formulaire_feuille_appel(formsemestre_id: int):
|
2024-07-12 16:40:46 +02:00
|
|
|
"""Formulaire de feuille d'appel
|
|
|
|
|
2024-08-23 17:59:55 +02:00
|
|
|
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>>
|
|
|
|
|
|
|
|
"""
|
2024-08-23 17:59:55 +02:00
|
|
|
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")
|
2024-08-23 17:59:55 +02:00
|
|
|
try:
|
2024-08-25 08:05:40 +02:00
|
|
|
group_ids = [int(gid) for gid in group_ids_list if gid]
|
2024-08-23 17:59:55 +02:00
|
|
|
except ValueError as exc:
|
2024-08-25 08:05:40 +02:00
|
|
|
log(f"formulaire_feuille_appel: group_ids invalide: {group_ids_list[:100]}")
|
2024-08-23 17:59:55 +02:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
2024-08-23 17:59:55 +02:00
|
|
|
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",
|
|
|
|
form=form,
|
|
|
|
group_name=groups_infos.groups_titles,
|
2024-08-25 08:05:40 +02:00
|
|
|
grp=menu_groups_choice(groups_infos),
|
2024-08-23 17:59:55 +02:00
|
|
|
formsemestre_id=formsemestre_id,
|
2024-09-03 04:44:48 +02:00
|
|
|
sco=ScoData(formsemestre=formsemestre),
|
2024-07-12 16:40:46 +02:00
|
|
|
)
|