forked from ScoDoc/ScoDoc
59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
|
""" """
|
||
|
|
||
|
from flask_wtf import FlaskForm
|
||
|
from wtforms import SelectField, RadioField, TextAreaField, validators, SubmitField
|
||
|
from app.scodoc.sco_utils import EtatAssiduite
|
||
|
|
||
|
|
||
|
class EditAssiForm(FlaskForm):
|
||
|
"""
|
||
|
Formulaire de modification d'une assiduité
|
||
|
"""
|
||
|
|
||
|
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)
|
||
|
|
||
|
def disable_all(self):
|
||
|
"Disable all fields"
|
||
|
for field in self:
|
||
|
field.render_kw = {"disabled": True}
|
||
|
|
||
|
assi_etat = RadioField(
|
||
|
"État:",
|
||
|
choices=[
|
||
|
(EtatAssiduite.ABSENT.value, EtatAssiduite.ABSENT.version_lisible()),
|
||
|
(EtatAssiduite.RETARD.value, EtatAssiduite.RETARD.version_lisible()),
|
||
|
(EtatAssiduite.PRESENT.value, EtatAssiduite.PRESENT.version_lisible()),
|
||
|
],
|
||
|
default="absent",
|
||
|
validators=[
|
||
|
validators.DataRequired("spécifiez le type d'évènement à signaler"),
|
||
|
],
|
||
|
)
|
||
|
modimpl = SelectField(
|
||
|
"Module",
|
||
|
choices={}, # will be populated dynamically
|
||
|
)
|
||
|
description = TextAreaField(
|
||
|
"Description",
|
||
|
render_kw={
|
||
|
"id": "description",
|
||
|
"cols": 75,
|
||
|
"rows": 4,
|
||
|
"maxlength": 500,
|
||
|
},
|
||
|
)
|
||
|
|
||
|
submit = SubmitField("Enregistrer")
|
||
|
cancel = SubmitField("Annuler", render_kw={"formnovalidate": True})
|