From 84a25ae15ba830e14dcf529106e086a9c7c043b2 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 14 Feb 2022 16:05:43 +0100 Subject: [PATCH] =?UTF-8?q?TF:=20am=C3=A9liore=20check=20min/max?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/TrivialFormulator.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/app/scodoc/TrivialFormulator.py b/app/scodoc/TrivialFormulator.py index 25442194f2..1cf4ea924c 100644 --- a/app/scodoc/TrivialFormulator.py +++ b/app/scodoc/TrivialFormulator.py @@ -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"])