Formulaires: check min/max integers and floats
This commit is contained in:
parent
257248aa2b
commit
6e525b3f02
@ -10,6 +10,7 @@
|
||||
"""
|
||||
import html
|
||||
import re
|
||||
import app.scodoc.sco_utils as scu
|
||||
|
||||
# re validant dd/mm/yyyy
|
||||
DMY_REGEXP = re.compile(
|
||||
@ -297,6 +298,20 @@ class TF(object):
|
||||
% (val, field, descr["max_value"])
|
||||
)
|
||||
ok = 0
|
||||
if typ[:3] == "int":
|
||||
if not (scu.DB_MIN_INT <= self.values[field] <= scu.DB_MAX_INT):
|
||||
msg.append(
|
||||
f"Le champ '{field}' est a une valeur hors limite"
|
||||
)
|
||||
ok = 0
|
||||
elif typ == "float" or typ == "real":
|
||||
if not (
|
||||
scu.DB_MIN_FLOAT <= self.values[field] <= scu.DB_MAX_FLOAT
|
||||
):
|
||||
msg.append(
|
||||
f"Le champ '{field}' est a une valeur hors limite"
|
||||
)
|
||||
ok = 0
|
||||
if ok and (typ[:3] == "str") and "max_length" in descr:
|
||||
if len(self.values[field]) > descr["max_length"]:
|
||||
msg.append(
|
||||
|
@ -466,6 +466,7 @@ def module_edit(
|
||||
"title": "Heures cours :",
|
||||
"size": 4,
|
||||
"type": "float",
|
||||
"min_value": 0,
|
||||
"explanation": "nombre d'heures de cours (optionnel)",
|
||||
},
|
||||
),
|
||||
@ -475,6 +476,7 @@ def module_edit(
|
||||
"title": "Heures de TD :",
|
||||
"size": 4,
|
||||
"type": "float",
|
||||
"min_value": 0,
|
||||
"explanation": "nombre d'heures de Travaux Dirigés (optionnel)",
|
||||
},
|
||||
),
|
||||
@ -484,6 +486,7 @@ def module_edit(
|
||||
"title": "Heures de TP :",
|
||||
"size": 4,
|
||||
"type": "float",
|
||||
"min_value": 0,
|
||||
"explanation": "nombre d'heures de Travaux Pratiques (optionnel)",
|
||||
},
|
||||
),
|
||||
|
@ -352,6 +352,8 @@ def ue_edit(ue_id=None, create=False, formation_id=None, default_semestre_idx=No
|
||||
{
|
||||
"size": 4,
|
||||
"type": "float",
|
||||
"min_value": 0,
|
||||
"max_value": 1000,
|
||||
"title": "ECTS",
|
||||
"explanation": "nombre de crédits ECTS (indiquer 0 si UE bonus)",
|
||||
"allow_null": not is_apc, # ects requis en APC
|
||||
@ -365,6 +367,7 @@ def ue_edit(ue_id=None, create=False, formation_id=None, default_semestre_idx=No
|
||||
{
|
||||
"size": 4,
|
||||
"type": "float",
|
||||
"min_value": 0,
|
||||
"title": "Coef. RCUE",
|
||||
"explanation": """pondération utilisée pour le calcul de la moyenne du RCUE. Laisser à 1, sauf si votre établissement a explicitement décidé de pondérations.
|
||||
""",
|
||||
@ -381,6 +384,7 @@ def ue_edit(ue_id=None, create=False, formation_id=None, default_semestre_idx=No
|
||||
{
|
||||
"size": 4,
|
||||
"type": "float",
|
||||
"min_value": 0,
|
||||
"title": "Coefficient",
|
||||
"explanation": """les coefficients d'UE ne sont utilisés que
|
||||
lorsque l'option <em>Utiliser les coefficients d'UE pour calculer
|
||||
|
@ -209,7 +209,7 @@ def evaluation_create_form(
|
||||
"coefficient",
|
||||
{
|
||||
"size": 6,
|
||||
"type": "float",
|
||||
"type": "float", # peut être négatif (!)
|
||||
"explanation": "coef. dans le module (choisi librement par l'enseignant, non utilisé pour rattrapage et 2ème session)",
|
||||
"allow_null": False,
|
||||
},
|
||||
|
@ -318,6 +318,8 @@ def external_ue_create_form(formsemestre_id: int, etudid: int):
|
||||
{
|
||||
"size": 4,
|
||||
"type": "float",
|
||||
"min_value": 0,
|
||||
"max_value": 1000,
|
||||
"title": "ECTS",
|
||||
"explanation": "nombre de crédits ECTS",
|
||||
"dom_id": "tf_extue_ects",
|
||||
|
@ -655,6 +655,13 @@ def to_bool(x) -> bool:
|
||||
return bool(x)
|
||||
|
||||
|
||||
# Min/Max values for numbers stored in database:
|
||||
DB_MIN_FLOAT = -1e30
|
||||
DB_MAX_FLOAT = 1e30
|
||||
DB_MIN_INT = -(1 << 31)
|
||||
DB_MAX_INT = (1 << 31) - 1
|
||||
|
||||
|
||||
def bul_filename_old(sem: dict, etud: dict, format):
|
||||
"""Build a filename for this bulletin"""
|
||||
dt = time.strftime("%Y-%m-%d")
|
||||
|
@ -1488,6 +1488,8 @@ def _etudident_create_or_edit_form(edit):
|
||||
"size": 5,
|
||||
"title": "Année bac",
|
||||
"type": "int",
|
||||
"min_value": 1945,
|
||||
"max_value": 2100,
|
||||
"explanation": "année obtention du bac",
|
||||
},
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user