diff --git a/app/scodoc/TrivialFormulator.py b/app/scodoc/TrivialFormulator.py index 25442194f..1cf4ea924 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"])