TF: améliore check min/max

This commit is contained in:
Emmanuel Viennet 2022-02-14 16:05:43 +01:00
parent 37fde88a74
commit 84a25ae15b

View File

@ -254,13 +254,13 @@ class TF(object):
continue # allowed empty field, skip
# type
typ = descr.get("type", "string")
if val != "" and val != None:
if val != "" and val is not None:
# check only non-null values
if typ[:3] == "int":
try:
val = int(val)
self.values[field] = val
except:
except ValueError:
msg.append(
"La valeur du champ '%s' doit être un nombre entier" % field
)
@ -270,30 +270,24 @@ class TF(object):
try:
val = float(val.replace(",", ".")) # allow ,
self.values[field] = val
except:
except ValueError:
msg.append(
"La valeur du champ '%s' doit être un nombre" % field
)
ok = 0
if typ[:3] == "int" or typ == "float" or typ == "real":
if (
val != ""
and val != None
and "min_value" in descr
and val < descr["min_value"]
):
if (
ok
and (typ[:3] == "int" or typ == "float" or typ == "real")
and val != ""
and val != None
):
if "min_value" in descr and self.values[field] < descr["min_value"]:
msg.append(
"La valeur (%d) du champ '%s' est trop petite (min=%s)"
% (val, field, descr["min_value"])
)
ok = 0
if (
val != ""
and val != None
and "max_value" in descr
and val > descr["max_value"]
):
if "max_value" in descr and self.values[field] > descr["max_value"]:
msg.append(
"La valeur (%s) du champ '%s' est trop grande (max=%s)"
% (val, field, descr["max_value"])