Fix: édition heures assiduité. Introduces ScoDateField/ScoTimeField.

This commit is contained in:
Emmanuel Viennet 2024-09-15 11:14:50 +02:00
parent 5ab733c1c6
commit c38b8aa297
5 changed files with 78 additions and 158 deletions

View File

@ -1,7 +1,9 @@
"""WTF Forms for ScoDoc """WTF Forms for ScoDoc
""" """
import re
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from wtforms import StringField, validators
class ScoDocForm(FlaskForm): class ScoDocForm(FlaskForm):
@ -21,3 +23,51 @@ class ScoDocForm(FlaskForm):
self.error_messages.append(err_msg) self.error_messages.append(err_msg)
if field: if field:
field.errors.append(err_msg) field.errors.append(err_msg)
class ScoDateField(StringField):
"""A WTF field for date, using datepicker"""
def __init__(self, label: str, field_id: str, *args, **kwargs):
render_kw = {
"class": "datepicker",
"size": 10,
"id": field_id,
}
if "render_kw" in kwargs:
render_kw.update(kwargs["render_kw"])
super().__init__(
label,
validators=[validators.Length(max=10)],
render_kw=render_kw,
*args,
**kwargs
)
class ScoTimeField(StringField):
"""A WTF field for time, accept 12:34, 12h34, 12H34
Uses timepicker
"""
def __init__(self, label: str, field_id: str, *args, **kwargs):
render_kw = {
"class": "timepicker",
"size": 5,
"id": field_id,
}
if "render_kw" in kwargs:
render_kw.update(kwargs["render_kw"])
super().__init__(
label,
validators=[validators.Length(max=5)],
default="",
render_kw=render_kw,
filters=[
lambda x: (
re.sub(r"(^\d{2})[hH](\d{2}$)", r"\1:\2", x.strip()) if x else None
)
],
*args,
**kwargs
)

View File

@ -34,14 +34,13 @@ from flask_wtf.file import MultipleFileField
from wtforms import ( from wtforms import (
BooleanField, BooleanField,
SelectField, SelectField,
StringField,
SubmitField, SubmitField,
RadioField, RadioField,
TextAreaField, TextAreaField,
validators, validators,
) )
from wtforms.validators import DataRequired from wtforms.validators import DataRequired
from app.scodoc import sco_utils as scu from app.forms import ScoDateField, ScoTimeField
class AjoutAssiOrJustForm(FlaskForm): class AjoutAssiOrJustForm(FlaskForm):
@ -67,64 +66,15 @@ class AjoutAssiOrJustForm(FlaskForm):
for field in self: for field in self:
field.render_kw = {"disabled": True} field.render_kw = {"disabled": True}
date_debut = StringField( date_debut = ScoDateField("Date de début", "assi_date_debut")
"Date de début", heure_debut = ScoTimeField("Heure début", "assi_heure_debut")
validators=[validators.Length(max=10)], heure_fin = ScoTimeField("Heure fin", "assi_heure_fin")
render_kw={
"class": "datepicker", date_fin = ScoDateField("Date de fin (si plusieurs jours)", "assi_date_fin")
"size": 10,
"id": "assi_date_debut", entry_date = ScoDateField("Date de dépôt ou saisie", "entry_date")
}, entry_time = ScoTimeField("Heure dépôt", "entry_time")
)
heure_debut = StringField(
"Heure début",
default="",
validators=[validators.Length(max=5)],
render_kw={
"class": "timepicker",
"size": 5,
"id": "assi_heure_debut",
},
)
heure_fin = StringField(
"Heure fin",
default="",
validators=[validators.Length(max=5)],
render_kw={
"class": "timepicker",
"size": 5,
"id": "assi_heure_fin",
},
)
date_fin = StringField(
"Date de fin (si plusieurs jours)",
validators=[validators.Length(max=10)],
render_kw={
"class": "datepicker",
"size": 10,
"id": "assi_date_fin",
},
)
entry_date = StringField(
"Date de dépôt ou saisie",
validators=[validators.Length(max=10)],
render_kw={
"class": "datepicker",
"size": 10,
"id": "entry_date",
},
)
entry_time = StringField(
"Heure dépôt",
default="",
validators=[validators.Length(max=5)],
render_kw={
"class": "timepicker",
"size": 5,
"id": "assi_heure_fin",
},
)
submit = SubmitField("Enregistrer") submit = SubmitField("Enregistrer")
cancel = SubmitField("Annuler", render_kw={"formnovalidate": True}) cancel = SubmitField("Annuler", render_kw={"formnovalidate": True})

View File

@ -1,14 +1,9 @@
""" """ """ """
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from wtforms import ( from wtforms import SelectField, RadioField, TextAreaField, validators, SubmitField
StringField,
SelectField, from app.forms import ScoDateField, ScoTimeField
RadioField,
TextAreaField,
validators,
SubmitField,
)
from app.scodoc.sco_utils import EtatAssiduite from app.scodoc.sco_utils import EtatAssiduite
@ -60,63 +55,13 @@ class EditAssiForm(FlaskForm):
"maxlength": 500, "maxlength": 500,
}, },
) )
date_debut = StringField( date_debut = ScoDateField("Date de début", "assi_date_debut")
"Date de début", heure_debut = ScoTimeField("Heure début", "assi_heure_debut")
validators=[validators.Length(max=10)], heure_fin = ScoTimeField("Heure fin", "assi_heure_fin")
render_kw={
"class": "datepicker", date_fin = ScoDateField("Date de fin", "assi_date_fin")
"size": 10, entry_date = ScoDateField("Date de dépôt ou saisie", "entry_date")
"id": "assi_date_debut", entry_time = ScoTimeField("Heure dépôt", "entry_time")
},
)
heure_debut = StringField(
"Heure début",
default="",
validators=[validators.Length(max=5)],
render_kw={
"class": "timepicker",
"size": 5,
"id": "assi_heure_debut",
},
)
heure_fin = StringField(
"Heure fin",
default="",
validators=[validators.Length(max=5)],
render_kw={
"class": "timepicker",
"size": 5,
"id": "assi_heure_fin",
},
)
date_fin = StringField(
"Date de fin",
validators=[validators.Length(max=10)],
render_kw={
"class": "datepicker",
"size": 10,
"id": "assi_date_fin",
},
)
entry_date = StringField(
"Date de dépôt ou saisie",
validators=[validators.Length(max=10)],
render_kw={
"class": "datepicker",
"size": 10,
"id": "entry_date",
},
)
entry_time = StringField(
"Heure dépôt",
default="",
validators=[validators.Length(max=5)],
render_kw={
"class": "timepicker",
"size": 5,
"id": "assi_heure_fin",
},
)
submit = SubmitField("Enregistrer") submit = SubmitField("Enregistrer")
cancel = SubmitField("Annuler", render_kw={"formnovalidate": True}) cancel = SubmitField("Annuler", render_kw={"formnovalidate": True})

View File

@ -28,7 +28,6 @@
""" """
Formulaire configuration Module Assiduités Formulaire configuration Module Assiduités
""" """
import datetime
import re import re
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
@ -36,7 +35,7 @@ from wtforms import DecimalField, SubmitField, ValidationError
from wtforms.fields.simple import StringField from wtforms.fields.simple import StringField
from wtforms.validators import Optional, Length from wtforms.validators import Optional, Length
from wtforms.widgets import TimeInput from app.forms import ScoDateField, ScoTimeField
def check_tick_time(form, field): def check_tick_time(form, field):
@ -77,36 +76,11 @@ def check_ics_regexp(form, field):
class ConfigAssiduitesForm(FlaskForm): class ConfigAssiduitesForm(FlaskForm):
"Formulaire paramétrage Module Assiduité" "Formulaire paramétrage Module Assiduité"
assi_morning_time = StringField( assi_morning_time = ScoTimeField("Début de la journée", "assi_morning_time")
"Début de la journée", assi_lunch_time = ScoTimeField(
default="", "Heure de midi (date pivot entre matin et après-midi)", "assi_lunch_time"
validators=[Length(max=5)],
render_kw={
"class": "timepicker",
"size": 5,
"id": "assi_morning_time",
},
)
assi_lunch_time = StringField(
"Heure de midi (date pivot entre matin et après-midi)",
default="",
validators=[Length(max=5)],
render_kw={
"class": "timepicker",
"size": 5,
"id": "assi_lunch_time",
},
)
assi_afternoon_time = StringField(
"Fin de la journée",
validators=[Length(max=5)],
default="",
render_kw={
"class": "timepicker",
"size": 5,
"id": "assi_afternoon_time",
},
) )
assi_afternoon_time = ScoTimeField("Fin de la journée", "assi_afternoon_time")
assi_tick_time = DecimalField( assi_tick_time = DecimalField(
"Granularité de la timeline (temps en minutes)", "Granularité de la timeline (temps en minutes)",

View File

@ -6,8 +6,9 @@
{{ super() }} {{ super() }}
<style> <style>
td.ue_s1 { table.gt_table {
color: red; border: 2px solid rgb(193, 165, 165);
border-collapse: collapse;
} }
/* bordures entre semestres */ /* bordures entre semestres */
@ -32,7 +33,7 @@ table.dataTable tbody tr:nth-child(odd) td.dtfc-fixed-start {
} }
table.dataTable tbody tr:nth-child(even), table.dataTable tbody tr:nth-child(even),
table.dataTable tbody tr:nth-child(even) td.dtfc-fixed-start { table.dataTable tbody tr:nth-child(even) td.dtfc-fixed-start {
background-color: rgb(253, 255, 240); background-color: rgb(254, 255, 246);
} }
</style> </style>