From ce80b9f7651acc6565555574165a2197012a8f46 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 23 Aug 2024 17:59:55 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20formulaire=5Ffeuille=5Fappel.=20A=20v?= =?UTF-8?q?=C3=A9rifier/simplifier=20=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/forms/scolar/groups_form.py | 4 +- app/scodoc/sco_groups_view.py | 7 +-- .../scolar/formulaire_feuille_appel.j2 | 28 +++++++++- app/views/groups.py | 51 ++++++++----------- 4 files changed, 56 insertions(+), 34 deletions(-) diff --git a/app/forms/scolar/groups_form.py b/app/forms/scolar/groups_form.py index 33a0d7521..1330224c4 100644 --- a/app/forms/scolar/groups_form.py +++ b/app/forms/scolar/groups_form.py @@ -53,4 +53,6 @@ class FeuilleAppelPreForm(FlaskForm): }, ) - submit = SubmitField("Télécharger la liste d'émargement") + submit = SubmitField( + "Télécharger la liste d'émargement", id="btn-submit", name="btn-submit" + ) diff --git a/app/scodoc/sco_groups_view.py b/app/scodoc/sco_groups_view.py index 541589bb5..3a16c98ff 100644 --- a/app/scodoc/sco_groups_view.py +++ b/app/scodoc/sco_groups_view.py @@ -39,7 +39,7 @@ from urllib.parse import parse_qs from flask import url_for, g, render_template, request from flask_login import current_user -from app import db +from app import db, log from app.models import FormSemestre, Identite, ScolarEvent import app.scodoc.sco_utils as scu from app.scodoc import html_sco_header @@ -225,7 +225,7 @@ def menu_groups_choice( submit_on_change=False, default_deselect_others=True, html_export=True, - change_event=None, + change_event=None, # XXX ??? ): """menu pour selection groupes group_ids est la liste des groupes actuellement sélectionnés @@ -369,6 +369,7 @@ class DisplayedGroupsInfos: try: group_ids = [int(g) for g in group_ids] except ValueError as exc: + log(f"DisplayedGroupsInfos: invalid group_id '{group_ids}'") raise ScoValueError( "identifiant de groupe invalide (mettre à jour vos bookmarks ?)" ) from exc @@ -973,7 +974,7 @@ def tab_absences_html(groups_infos, etat=None): scodoc_dept=g.scodoc_dept, formsemestre_id=groups_infos.formsemestre_id, ) - + "&" + + "?" + groups_infos.groups_query_args ) diff --git a/app/templates/scolar/formulaire_feuille_appel.j2 b/app/templates/scolar/formulaire_feuille_appel.j2 index ea7f133a5..8c93e15e7 100644 --- a/app/templates/scolar/formulaire_feuille_appel.j2 +++ b/app/templates/scolar/formulaire_feuille_appel.j2 @@ -19,7 +19,13 @@

Préparation de la feuille d'émargement : {{group_name}}

-
+ + {{ form.hidden_tag() }}
Groupes : {{grp|safe}}
@@ -50,4 +56,24 @@ {% include "sco_timepicker.j2" %} + {% endblock scripts %} \ No newline at end of file diff --git a/app/views/groups.py b/app/views/groups.py index 4f8e815dc..2dc869321 100644 --- a/app/views/groups.py +++ b/app/views/groups.py @@ -5,16 +5,15 @@ Nouvelles vues pour les groupes from flask import render_template, request - +from app import log from app.decorators import ( scodoc, permission_required, ) from app.forms.scolar import groups_form -from app.models import ( - FormSemestre, -) +from app.models import FormSemestre from app.scodoc.sco_excel import excel_feuille_listeappel +from app.scodoc.sco_exceptions import ScoValueError 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 @@ -22,34 +21,35 @@ from app.views import ScoData from app.views import scolar_bp as bp -@bp.route("/formulaire_feuille_appel", methods=["GET", "POST"]) +@bp.route("/formulaire_feuille_appel/", methods=["GET", "POST"]) @scodoc @permission_required(Permission.ScoView) -def formulaire_feuille_appel(): +def formulaire_feuille_appel(formsemestre_id: int): """Formulaire de feuille d'appel - GET : Affiche le formulaire de remplissage de la feuille d'appel - POST : Retourne la feuille d'appelle correspondante + GET Affiche le formulaire de remplissage de la feuille d'appel + POST (soumission) retourne la feuille d'appel 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.get_formsemestre(formsemestre_id) - formsemestre: 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: + group_ids_str = request.form.get("group_ids") + try: + group_ids = [int(gid) for gid in group_ids_str.split(",") if gid] + except ValueError as exc: + log(f"formulaire_feuille_appel: group_ids invalide: {group_ids_str[:100]}") + raise ScoValueError("groupes invalides") from exc + data = {} - group_ids: list[int] = request.args.getlist("group_ids") - - form: groups_form.FeuilleAppelPreForm = groups_form.FeuilleAppelPreForm( - request.form - ) + form = groups_form.FeuilleAppelPreForm(request.form, data=data) groups_infos = DisplayedGroupsInfos( group_ids, @@ -57,7 +57,7 @@ def formulaire_feuille_appel(): select_all_when_unspecified=True, ) - if request.method == "POST": + if form.validate_on_submit(): edt_params: dict = { "date": form.date.data or "", "heure": form.heure.data or "", @@ -65,14 +65,6 @@ def formulaire_feuille_appel(): "ens": form.ens.data or "", } - form_group_ids: list[str] = request.form.get("group_ids", "").split(",") - 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, @@ -90,4 +82,5 @@ def formulaire_feuille_appel(): form=form, group_name=groups_infos.groups_titles, grp=menu_groups_choice(groups_infos, html_export=False), + formsemestre_id=formsemestre_id, )