forked from ScoDoc/ScoDoc
Fix formulaire_feuille_appel. A vérifier/simplifier ?
This commit is contained in:
parent
6ab027dffe
commit
ce80b9f765
@ -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"
|
||||||
|
)
|
||||||
|
@ -39,7 +39,7 @@ from urllib.parse import parse_qs
|
|||||||
from flask import url_for, g, render_template, request
|
from flask import url_for, g, render_template, request
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
|
|
||||||
from app import db
|
from app import db, log
|
||||||
from app.models import FormSemestre, Identite, ScolarEvent
|
from app.models import FormSemestre, Identite, ScolarEvent
|
||||||
import app.scodoc.sco_utils as scu
|
import app.scodoc.sco_utils as scu
|
||||||
from app.scodoc import html_sco_header
|
from app.scodoc import html_sco_header
|
||||||
@ -225,7 +225,7 @@ def menu_groups_choice(
|
|||||||
submit_on_change=False,
|
submit_on_change=False,
|
||||||
default_deselect_others=True,
|
default_deselect_others=True,
|
||||||
html_export=True,
|
html_export=True,
|
||||||
change_event=None,
|
change_event=None, # XXX ???
|
||||||
):
|
):
|
||||||
"""menu pour selection groupes
|
"""menu pour selection groupes
|
||||||
group_ids est la liste des groupes actuellement sélectionnés
|
group_ids est la liste des groupes actuellement sélectionnés
|
||||||
@ -369,6 +369,7 @@ class DisplayedGroupsInfos:
|
|||||||
try:
|
try:
|
||||||
group_ids = [int(g) for g in group_ids]
|
group_ids = [int(g) for g in group_ids]
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
|
log(f"DisplayedGroupsInfos: invalid group_id '{group_ids}'")
|
||||||
raise ScoValueError(
|
raise ScoValueError(
|
||||||
"identifiant de groupe invalide (mettre à jour vos bookmarks ?)"
|
"identifiant de groupe invalide (mettre à jour vos bookmarks ?)"
|
||||||
) from exc
|
) from exc
|
||||||
@ -973,7 +974,7 @@ def tab_absences_html(groups_infos, etat=None):
|
|||||||
scodoc_dept=g.scodoc_dept,
|
scodoc_dept=g.scodoc_dept,
|
||||||
formsemestre_id=groups_infos.formsemestre_id,
|
formsemestre_id=groups_infos.formsemestre_id,
|
||||||
)
|
)
|
||||||
+ "&"
|
+ "?"
|
||||||
+ groups_infos.groups_query_args
|
+ groups_infos.groups_query_args
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,7 +19,13 @@
|
|||||||
<h2>Préparation de la feuille d'émargement : <span style="color:crimson">{{group_name}}</span></h2>
|
<h2>Préparation de la feuille d'émargement : <span style="color:crimson">{{group_name}}</span></h2>
|
||||||
|
|
||||||
<div class="scobox">
|
<div class="scobox">
|
||||||
<form action="" method="post">
|
<form
|
||||||
|
id="feuille_emargement"
|
||||||
|
action="{{request.base_url}}"
|
||||||
|
method="post"
|
||||||
|
onsubmit="serializeGroupIds(event)"
|
||||||
|
>
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
<div class="infos-button">Groupes : {{grp|safe}}</div>
|
<div class="infos-button">Groupes : {{grp|safe}}</div>
|
||||||
|
|
||||||
<div class="part">
|
<div class="part">
|
||||||
@ -50,4 +56,24 @@
|
|||||||
{% include "sco_timepicker.j2" %}
|
{% include "sco_timepicker.j2" %}
|
||||||
<script src="{{scu.STATIC_DIR}}/js/groups_view.js"></script>
|
<script src="{{scu.STATIC_DIR}}/js/groups_view.js"></script>
|
||||||
<script src="{{scu.STATIC_DIR}}/libjs/purl.js"></script>
|
<script src="{{scu.STATIC_DIR}}/libjs/purl.js"></script>
|
||||||
|
<script>
|
||||||
|
function serializeGroupIds(event) {
|
||||||
|
// Dealing with multiselect
|
||||||
|
event.preventDefault();
|
||||||
|
var form = document.getElementById("feuille_emargement");
|
||||||
|
var groupIdsField = form.elements["group_ids"];
|
||||||
|
|
||||||
|
// Check if the group_ids field exists and is an array
|
||||||
|
if (groupIdsField && Array.isArray(groupIdsField.value)) {
|
||||||
|
// Convert the array to a comma-separated string
|
||||||
|
var serializedValue = groupIdsField.value.join(',');
|
||||||
|
|
||||||
|
// Replace the field's value with the serialized string
|
||||||
|
groupIdsField.value = serializedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now submit the form
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{% endblock scripts %}
|
{% endblock scripts %}
|
@ -5,16 +5,15 @@ Nouvelles vues pour les groupes
|
|||||||
|
|
||||||
from flask import render_template, request
|
from flask import render_template, request
|
||||||
|
|
||||||
|
from app import log
|
||||||
from app.decorators import (
|
from app.decorators import (
|
||||||
scodoc,
|
scodoc,
|
||||||
permission_required,
|
permission_required,
|
||||||
)
|
)
|
||||||
from app.forms.scolar import groups_form
|
from app.forms.scolar import groups_form
|
||||||
from app.models import (
|
from app.models import FormSemestre
|
||||||
FormSemestre,
|
|
||||||
)
|
|
||||||
from app.scodoc.sco_excel import excel_feuille_listeappel
|
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_groups_view import DisplayedGroupsInfos, menu_groups_choice
|
||||||
from app.scodoc.sco_permissions import Permission
|
from app.scodoc.sco_permissions import Permission
|
||||||
from app.scodoc import sco_utils as scu
|
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
|
from app.views import scolar_bp as bp
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/formulaire_feuille_appel", methods=["GET", "POST"])
|
@bp.route("/formulaire_feuille_appel/<int:formsemestre_id>", methods=["GET", "POST"])
|
||||||
@scodoc
|
@scodoc
|
||||||
@permission_required(Permission.ScoView)
|
@permission_required(Permission.ScoView)
|
||||||
def formulaire_feuille_appel():
|
def formulaire_feuille_appel(formsemestre_id: int):
|
||||||
"""Formulaire de feuille d'appel
|
"""Formulaire de feuille d'appel
|
||||||
|
|
||||||
GET : Affiche le formulaire de remplissage de la feuille d'appel
|
GET Affiche le formulaire de remplissage de la feuille d'appel
|
||||||
POST : Retourne la feuille d'appelle correspondante
|
POST (soumission) retourne la feuille d'appel correspondante
|
||||||
|
|
||||||
QUERY
|
QUERY
|
||||||
-----
|
-----
|
||||||
formsemestre_id:<int:formsemestre_id>
|
|
||||||
group_ids:<list:<int:group_id>>
|
group_ids:<list:<int:group_id>>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
formsemestre_id: int = request.args.get("formsemestre_id")
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
||||||
try:
|
|
||||||
formsemestre_id = int(formsemestre_id)
|
|
||||||
except ValueError:
|
|
||||||
formsemestre_id = None
|
|
||||||
|
|
||||||
formsemestre: FormSemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
||||||
|
|
||||||
|
if request.method == "GET":
|
||||||
group_ids: list[int] = request.args.getlist("group_ids")
|
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 = {}
|
||||||
|
|
||||||
form: groups_form.FeuilleAppelPreForm = groups_form.FeuilleAppelPreForm(
|
form = groups_form.FeuilleAppelPreForm(request.form, data=data)
|
||||||
request.form
|
|
||||||
)
|
|
||||||
|
|
||||||
groups_infos = DisplayedGroupsInfos(
|
groups_infos = DisplayedGroupsInfos(
|
||||||
group_ids,
|
group_ids,
|
||||||
@ -57,7 +57,7 @@ def formulaire_feuille_appel():
|
|||||||
select_all_when_unspecified=True,
|
select_all_when_unspecified=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if request.method == "POST":
|
if form.validate_on_submit():
|
||||||
edt_params: dict = {
|
edt_params: dict = {
|
||||||
"date": form.date.data or "",
|
"date": form.date.data or "",
|
||||||
"heure": form.heure.data or "",
|
"heure": form.heure.data or "",
|
||||||
@ -65,14 +65,6 @@ def formulaire_feuille_appel():
|
|||||||
"ens": form.ens.data or "",
|
"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(
|
xls = excel_feuille_listeappel(
|
||||||
groups_infos.formsemestre,
|
groups_infos.formsemestre,
|
||||||
groups_infos.groups_titles,
|
groups_infos.groups_titles,
|
||||||
@ -90,4 +82,5 @@ def formulaire_feuille_appel():
|
|||||||
form=form,
|
form=form,
|
||||||
group_name=groups_infos.groups_titles,
|
group_name=groups_infos.groups_titles,
|
||||||
grp=menu_groups_choice(groups_infos, html_export=False),
|
grp=menu_groups_choice(groups_infos, html_export=False),
|
||||||
|
formsemestre_id=formsemestre_id,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user