forked from ScoDoc/ScoDoc
Assiduites : choix date quand date courante hors semestre fixes #837
This commit is contained in:
parent
0fa35708f9
commit
7d441b1c4d
@ -161,3 +161,30 @@ class AjoutJustificatifEtudForm(AjoutAssiOrJustForm):
|
||||
validators=[DataRequired(message="This field is required.")],
|
||||
)
|
||||
fichiers = MultipleFileField(label="Ajouter des fichiers")
|
||||
|
||||
|
||||
class ChoixDateForm(FlaskForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
"Init form, adding a filed for our error messages"
|
||||
super().__init__(*args, **kwargs)
|
||||
self.ok = True
|
||||
self.error_messages: list[str] = [] # used to report our errors
|
||||
|
||||
def set_error(self, err_msg, field=None):
|
||||
"Set error message both in form and field"
|
||||
self.ok = False
|
||||
self.error_messages.append(err_msg)
|
||||
if field:
|
||||
field.errors.append(err_msg)
|
||||
|
||||
date = StringField(
|
||||
"Date",
|
||||
validators=[validators.Length(max=10)],
|
||||
render_kw={
|
||||
"class": "datepicker",
|
||||
"size": 10,
|
||||
"id": "date",
|
||||
},
|
||||
)
|
||||
submit = SubmitField("Enregistrer")
|
||||
cancel = SubmitField("Annuler", render_kw={"formnovalidate": True})
|
||||
|
30
app/templates/assiduites/pages/choix_date.j2
Normal file
30
app/templates/assiduites/pages/choix_date.j2
Normal file
@ -0,0 +1,30 @@
|
||||
{% extends "sco_page.j2" %}
|
||||
{% import 'wtf.j2' as wtf %}
|
||||
|
||||
{% block styles %}
|
||||
{{super()}}
|
||||
<link rel="stylesheet" href="{{scu.STATIC_DIR}}/libjs/timepicker-1.3.5/jquery.timepicker.min.css"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block app_content %}
|
||||
{% for err_msg in form.error_messages %}
|
||||
<div class="wtf-error-messages">
|
||||
{{ err_msg }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<h2>La date courante n'est pas dans le semestre ({{deb}} -> {{fin}})</h2>
|
||||
<h2>Choissez une autre date</h2>
|
||||
|
||||
<form action="" method="post">
|
||||
{{ form.hidden_tag() }}
|
||||
{{ form.date.label }} : {{ form.date }}
|
||||
<div class="submit">
|
||||
{{ form.submit }} {{ form.cancel }}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% endblock app_content %}
|
||||
{% block scripts %}
|
||||
{{ super() }}
|
||||
<script src="{{scu.STATIC_DIR}}/libjs/timepicker-1.3.5/jquery.timepicker.min.js"></script>
|
||||
{% endblock scripts %}
|
@ -43,6 +43,7 @@ from app.forms.assiduite.ajout_assiduite_etud import (
|
||||
AjoutAssiOrJustForm,
|
||||
AjoutAssiduiteEtudForm,
|
||||
AjoutJustificatifEtudForm,
|
||||
ChoixDateForm,
|
||||
)
|
||||
from app.models import (
|
||||
Assiduite,
|
||||
@ -891,6 +892,56 @@ def calendrier_assi_etud():
|
||||
).build()
|
||||
|
||||
|
||||
@bp.route("/choix_date", methods=["GET", "POST"])
|
||||
@scodoc
|
||||
@permission_required(Permission.AbsChange)
|
||||
def choix_date() -> str:
|
||||
formsemestre_id = request.args.get("formsemestre_id")
|
||||
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
||||
|
||||
group_ids = request.args.get("group_ids")
|
||||
moduleimpl_id = request.args.get("moduleimpl_id")
|
||||
form = ChoixDateForm(request.form)
|
||||
|
||||
if form.validate_on_submit():
|
||||
if form.cancel.data:
|
||||
return redirect(url_for("scodoc.index"))
|
||||
# Vérifier si date dans semestre
|
||||
ok: bool = False
|
||||
try:
|
||||
date: datetime.date = datetime.datetime.strptime(
|
||||
form.date.data, "%d/%m/%Y"
|
||||
).date()
|
||||
if date < formsemestre.date_debut or date > formsemestre.date_fin:
|
||||
form.set_error(
|
||||
"La date sélectionnée n'est pas dans le semestre.", form.date
|
||||
)
|
||||
else:
|
||||
ok = True
|
||||
except ValueError:
|
||||
form.set_error("Date invalide", form.date)
|
||||
|
||||
if ok:
|
||||
return redirect(
|
||||
url_for(
|
||||
"assiduites.signal_assiduites_group",
|
||||
scodoc_dept=g.scodoc_dept,
|
||||
formsemestre_id=formsemestre_id,
|
||||
group_ids=group_ids,
|
||||
moduleimpl_id=moduleimpl_id,
|
||||
jour=date.isoformat(),
|
||||
)
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"assiduites/pages/choix_date.j2",
|
||||
form=form,
|
||||
sco=ScoData(formsemestre=formsemestre),
|
||||
deb=formsemestre.date_debut.strftime("%d/%m/%Y"),
|
||||
fin=formsemestre.date_fin.strftime("%d/%m/%Y"),
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/signal_assiduites_group")
|
||||
@scodoc
|
||||
@permission_required(Permission.AbsChange)
|
||||
@ -962,15 +1013,15 @@ def signal_assiduites_group():
|
||||
real_date = scu.is_iso_formated(date, True).date()
|
||||
|
||||
if real_date < formsemestre.date_debut or real_date > formsemestre.date_fin:
|
||||
# Si le jour est hors semestre, indiquer une erreur
|
||||
|
||||
# Formatage des dates pour le message d'erreur
|
||||
real_str = real_date.strftime("%d/%m/%Y")
|
||||
form_deb = formsemestre.date_debut.strftime("%d/%m/%Y")
|
||||
form_fin = formsemestre.date_fin.strftime("%d/%m/%Y")
|
||||
raise ScoValueError(
|
||||
f"Impossible de saisir l'assiduité pour le {real_str}"
|
||||
+ f" : Jour en dehors du semestre ( {form_deb} → {form_fin}) "
|
||||
# Si le jour est hors semestre, renvoyer vers choix date
|
||||
return redirect(
|
||||
url_for(
|
||||
"assiduites.choix_date",
|
||||
formsemestre_id=formsemestre_id,
|
||||
group_ids=group_ids,
|
||||
moduleimpl_id=moduleimpl_id,
|
||||
scodoc_dept=g.scodoc_dept,
|
||||
)
|
||||
)
|
||||
|
||||
# --- Restriction en fonction du moduleimpl_id ---
|
||||
|
Loading…
Reference in New Issue
Block a user