From 7a7c2f1778a248780a842c6c2e43cb647bd93a68 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 21 Feb 2023 02:08:50 +0100 Subject: [PATCH] Fix: formulaires: saisie nombres/ exception --- app/scodoc/TrivialFormulator.py | 17 ++++++++++++++--- sco_version.py | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/scodoc/TrivialFormulator.py b/app/scodoc/TrivialFormulator.py index f3c768a2..0c7e3762 100644 --- a/app/scodoc/TrivialFormulator.py +++ b/app/scodoc/TrivialFormulator.py @@ -370,12 +370,23 @@ class TF(object): self.values[field] = True else: self.values[field] = False - # open('/tmp/toto','a').write('checkvalues: val=%s (%s) values[%s] = %s\n' % (val, type(val), field, self.values[field])) if descr.get("convert_numbers", False): if typ[:3] == "int": - self.values[field] = int(self.values[field]) + try: + self.values[field] = int(self.values[field]) + except ValueError: + msg.append( + f"valeur invalide ({self.values[field]}) pour le champs {field}" + ) + ok = False elif typ == "float" or typ == "real": - self.values[field] = float(self.values[field].replace(",", ".")) + try: + self.values[field] = float(self.values[field].replace(",", ".")) + except ValueError: + msg.append( + f"valeur invalide ({self.values[field]}) pour le champs {field}" + ) + ok = False if ok: self.result = self.values else: diff --git a/sco_version.py b/sco_version.py index 63669db8..6fe40c05 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.4.46" +SCOVERSION = "9.4.47" SCONAME = "ScoDoc"