2023-04-25 22:59:06 +02:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# ScoDoc
|
|
|
|
#
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2023-04-25 22:59:06 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# Emmanuel Viennet emmanuel.viennet@viennet.net
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
Formulaire configuration Module Assiduités
|
|
|
|
"""
|
2023-11-08 23:19:58 +01:00
|
|
|
import datetime
|
2023-11-13 15:08:09 +01:00
|
|
|
import re
|
2023-04-25 22:59:06 +02:00
|
|
|
|
|
|
|
from flask_wtf import FlaskForm
|
2023-11-08 23:19:58 +01:00
|
|
|
from wtforms import DecimalField, SubmitField, ValidationError
|
2023-04-25 22:59:06 +02:00
|
|
|
from wtforms.fields.simple import StringField
|
2023-11-08 23:19:58 +01:00
|
|
|
from wtforms.validators import Optional
|
|
|
|
|
2023-04-25 22:59:06 +02:00
|
|
|
from wtforms.widgets import TimeInput
|
|
|
|
|
|
|
|
|
|
|
|
class TimeField(StringField):
|
2023-10-27 16:05:40 +02:00
|
|
|
"""HTML5 time input.
|
|
|
|
tiré de : https://gist.github.com/tachyondecay/6016d32f65a996d0d94f
|
|
|
|
"""
|
2023-04-25 22:59:06 +02:00
|
|
|
|
|
|
|
widget = TimeInput()
|
|
|
|
|
|
|
|
def __init__(self, label=None, validators=None, fmt="%H:%M:%S", **kwargs):
|
|
|
|
super(TimeField, self).__init__(label, validators, **kwargs)
|
|
|
|
self.fmt = fmt
|
|
|
|
self.data = None
|
|
|
|
|
|
|
|
def _value(self):
|
|
|
|
if self.raw_data:
|
|
|
|
return " ".join(self.raw_data)
|
|
|
|
if self.data and isinstance(self.data, str):
|
|
|
|
self.data = datetime.time(*map(int, self.data.split(":")))
|
|
|
|
return self.data and self.data.strftime(self.fmt) or ""
|
|
|
|
|
|
|
|
def process_formdata(self, valuelist):
|
|
|
|
if valuelist:
|
|
|
|
time_str = " ".join(valuelist)
|
|
|
|
try:
|
|
|
|
components = time_str.split(":")
|
|
|
|
hour = 0
|
|
|
|
minutes = 0
|
|
|
|
seconds = 0
|
|
|
|
if len(components) in range(2, 4):
|
|
|
|
hour = int(components[0])
|
|
|
|
minutes = int(components[1])
|
|
|
|
|
|
|
|
if len(components) == 3:
|
|
|
|
seconds = int(components[2])
|
|
|
|
else:
|
|
|
|
raise ValueError
|
|
|
|
self.data = datetime.time(hour, minutes, seconds)
|
2023-11-08 23:19:58 +01:00
|
|
|
except ValueError as exc:
|
2023-04-25 22:59:06 +02:00
|
|
|
self.data = None
|
2023-11-08 23:19:58 +01:00
|
|
|
raise ValueError(self.gettext("Not a valid time string")) from exc
|
|
|
|
|
|
|
|
|
|
|
|
def check_tick_time(form, field):
|
|
|
|
"""Le tick_time doit être entre 0 et 60 minutes"""
|
|
|
|
if field.data < 1 or field.data > 59:
|
|
|
|
raise ValidationError("Valeur de granularité invalide (entre 1 et 59)")
|
|
|
|
|
|
|
|
|
|
|
|
def check_ics_path(form, field):
|
|
|
|
"""Vérifie que le chemin est bien un chemin absolu
|
|
|
|
et qu'il contient edt_id
|
|
|
|
"""
|
|
|
|
data = field.data.strip()
|
|
|
|
if not data:
|
|
|
|
return
|
|
|
|
if not data.startswith("/"):
|
|
|
|
raise ValidationError("Le chemin vers les ics doit commencer par /")
|
|
|
|
if not "{edt_id}" in data:
|
|
|
|
raise ValidationError("Le chemin vers les ics doit utiliser {edt_id}")
|
2023-04-25 22:59:06 +02:00
|
|
|
|
|
|
|
|
2023-11-13 15:08:09 +01:00
|
|
|
def check_ics_field(form, field):
|
|
|
|
"""Vérifie que c'est un nom de champ crédible: un mot alphanumérique"""
|
|
|
|
if not re.match(r"^[a-zA-Z\-_0-9]+$", field.data):
|
|
|
|
raise ValidationError("nom de champ ics invalide")
|
|
|
|
|
|
|
|
|
|
|
|
def check_ics_regexp(form, field):
|
|
|
|
"""Vérifie que field est une expresssion régulière"""
|
|
|
|
value = field.data.strip()
|
|
|
|
# check that it compiles
|
|
|
|
try:
|
|
|
|
_ = re.compile(value)
|
|
|
|
except re.error as exc:
|
|
|
|
raise ValidationError("expression invalide") from exc
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2023-04-25 22:59:06 +02:00
|
|
|
class ConfigAssiduitesForm(FlaskForm):
|
2023-09-21 08:46:21 +02:00
|
|
|
"Formulaire paramétrage Module Assiduité"
|
2023-04-25 22:59:06 +02:00
|
|
|
|
2024-01-05 10:06:16 +01:00
|
|
|
assi_morning_time = TimeField(
|
2023-12-29 06:19:20 +01:00
|
|
|
"Début de la journée"
|
|
|
|
) # TODO utiliser TextField + timepicker voir AjoutAssiOrJustForm
|
2024-01-05 10:06:16 +01:00
|
|
|
assi_lunch_time = TimeField(
|
2023-12-29 06:19:20 +01:00
|
|
|
"Heure de midi (date pivot entre matin et après-midi)"
|
|
|
|
) # TODO
|
2024-01-05 10:06:16 +01:00
|
|
|
assi_afternoon_time = TimeField("Fin de la journée") # TODO
|
2023-04-25 22:59:06 +02:00
|
|
|
|
2024-01-05 10:06:16 +01:00
|
|
|
assi_tick_time = DecimalField(
|
2023-11-08 23:19:58 +01:00
|
|
|
"Granularité de la timeline (temps en minutes)",
|
|
|
|
places=0,
|
|
|
|
validators=[check_tick_time],
|
|
|
|
)
|
|
|
|
|
|
|
|
edt_ics_path = StringField(
|
|
|
|
label="Chemin vers les ics",
|
|
|
|
description="""Chemin absolu unix sur le serveur vers le fichier ics donnant l'emploi
|
|
|
|
du temps d'un semestre. La balise <tt>{edt_id}</tt> sera remplacée par l'edt_id du
|
|
|
|
semestre (par défaut, son code étape Apogée).
|
|
|
|
Si ce champ n'est pas renseigné, les emplois du temps ne seront pas utilisés.""",
|
|
|
|
validators=[Optional(), check_ics_path],
|
|
|
|
)
|
2024-01-02 23:05:08 +01:00
|
|
|
edt_ics_user_path = StringField(
|
|
|
|
label="Chemin vers les ics des utilisateurs (enseignants)",
|
|
|
|
description="""Optionnel. Chemin absolu unix sur le serveur vers le fichier ics donnant l'emploi
|
|
|
|
du temps d'un enseignant. La balise <tt>{edt_id}</tt> sera remplacée par l'edt_id du
|
|
|
|
de l'utilisateur.
|
|
|
|
Dans certains cas (XXX), ScoDoc peut générer ces fichiers et les écrira suivant
|
|
|
|
ce chemin (avec edt_id).
|
|
|
|
""",
|
|
|
|
validators=[Optional(), check_ics_path],
|
|
|
|
)
|
2023-05-30 10:17:49 +02:00
|
|
|
|
2023-11-13 15:08:09 +01:00
|
|
|
edt_ics_title_field = StringField(
|
2023-12-28 23:05:19 +01:00
|
|
|
label="Champ contenant le titre",
|
2023-11-13 15:08:09 +01:00
|
|
|
description="""champ de l'évènement calendrier: DESCRIPTION, SUMMARY, ...""",
|
|
|
|
validators=[Optional(), check_ics_field],
|
|
|
|
)
|
|
|
|
edt_ics_title_regexp = StringField(
|
|
|
|
label="Extraction du titre",
|
|
|
|
description=r"""expression régulière python dont le premier groupe doit
|
|
|
|
sera le titre de l'évènement affcihé dans le calendrier ScoDoc.
|
|
|
|
Exemple: <tt>Matière : \w+ - ([\w\.\s']+)</tt>
|
|
|
|
""",
|
|
|
|
validators=[Optional(), check_ics_regexp],
|
|
|
|
)
|
|
|
|
edt_ics_group_field = StringField(
|
2023-12-28 23:05:19 +01:00
|
|
|
label="Champ contenant le groupe",
|
2023-11-13 15:08:09 +01:00
|
|
|
description="""champ de l'évènement calendrier: DESCRIPTION, SUMMARY, ...""",
|
|
|
|
validators=[Optional(), check_ics_field],
|
|
|
|
)
|
|
|
|
edt_ics_group_regexp = StringField(
|
|
|
|
label="Extraction du groupe",
|
|
|
|
description=r"""expression régulière python dont le premier groupe doit
|
|
|
|
correspondre à l'identifiant de groupe de l'emploi du temps.
|
|
|
|
Exemple: <tt>.*- ([\w\s]+)$</tt>
|
|
|
|
""",
|
|
|
|
validators=[Optional(), check_ics_regexp],
|
|
|
|
)
|
|
|
|
edt_ics_mod_field = StringField(
|
2023-12-28 23:05:19 +01:00
|
|
|
label="Champ contenant le module",
|
2023-11-13 15:08:09 +01:00
|
|
|
description="""champ de l'évènement calendrier: DESCRIPTION, SUMMARY, ...""",
|
|
|
|
validators=[Optional(), check_ics_field],
|
|
|
|
)
|
|
|
|
edt_ics_mod_regexp = StringField(
|
|
|
|
label="Extraction du module",
|
|
|
|
description=r"""expression régulière python dont le premier groupe doit
|
|
|
|
correspondre à l'identifiant (code) du module de l'emploi du temps.
|
|
|
|
Exemple: <tt>Matière : ([A-Z][A-Z0-9]+)</tt>
|
|
|
|
""",
|
|
|
|
validators=[Optional(), check_ics_regexp],
|
|
|
|
)
|
2023-12-28 23:05:19 +01:00
|
|
|
edt_ics_uid_field = StringField(
|
|
|
|
label="Champ contenant l'enseignant",
|
|
|
|
description="""champ de l'évènement calendrier: DESCRIPTION, SUMMARY, ...""",
|
|
|
|
validators=[Optional(), check_ics_field],
|
|
|
|
)
|
|
|
|
edt_ics_uid_regexp = StringField(
|
|
|
|
label="Extraction de l'enseignant",
|
|
|
|
description=r"""expression régulière python dont le premier groupe doit
|
|
|
|
correspondre à l'identifiant (edt_id) de l'enseignant associé à l'évènement.
|
|
|
|
Exemple: <tt>Enseignant : ([0-9]+)</tt>
|
|
|
|
""",
|
|
|
|
validators=[Optional(), check_ics_regexp],
|
|
|
|
)
|
2023-04-25 22:59:06 +02:00
|
|
|
submit = SubmitField("Valider")
|
|
|
|
cancel = SubmitField("Annuler", render_kw={"formnovalidate": True})
|