""" Nouvelles vues pour les groupes (aux normes ScoDoc9) """ from flask import render_template, request from app.decorators import ( scodoc, permission_required, ) from app.forms.scolar import groups_form from app.models import ( FormSemestre, ) from app.scodoc.sco_excel import excel_feuille_listeappel 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", methods=["GET", "POST"]) @scodoc @permission_required(Permission.ScoView) def formulaire_feuille_appel(): """Formulaire de feuille d'appel GET : Affiche le formulaire de remplissage de la feuille d'appel POST : Retourne la feuille d'appelle correspondante QUERY ----- formsemestre_id: group_ids:> """ formsemestre_id: int = request.args.get("formsemestre_id") try: formsemestre_id = int(formsemestre_id) except ValueError: formsemestre_id = None formsemestre: FormSemestre = FormSemestre.get_formsemestre(formsemestre_id) group_ids: list[int] = request.args.get("group_ids", "").split(",") form: groups_form.FeuilleAppelPreForm = groups_form.FeuilleAppelPreForm( request.form ) groups_infos = DisplayedGroupsInfos( group_ids, formsemestre_id=formsemestre_id, select_all_when_unspecified=True, ) if request.method == "POST": edt_params: dict = { "date": form.date.data or "", "heure": form.heure.data or "", "discipline": form.discipline.data or "", "ens": form.ens.data or "", } form_group_ids: list[str] = request.form.getlist("group_ids") if form_group_ids: groups_infos = DisplayedGroupsInfos( form_group_ids, formsemestre_id=formsemestre_id, select_all_when_unspecified=True, ) 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, grp=menu_groups_choice(groups_infos), )