[edition] convert integer and float values coming from edit forms so that values are correctly typed in before_xxx hooks stable
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 02 Sep 2009 09:30:50 +0200
branchstable
changeset 3092 c153b1ae9875
parent 3091 c3d73cecb29e
child 3093 12a69f7f963b
[edition] convert integer and float values coming from edit forms so that values are correctly typed in before_xxx hooks
web/views/editcontroller.py
--- a/web/views/editcontroller.py	Wed Sep 02 09:29:19 2009 +0200
+++ b/web/views/editcontroller.py	Wed Sep 02 09:30:50 2009 +0200
@@ -191,7 +191,22 @@
             return
         attrtype = rschema.objects(entity.e_schema)[0].type
         # on checkbox or selection, the field may not be in params
-        if attrtype == 'Boolean':
+        # NOTE: raising ValidationError here is not a good solution because
+        #       we can't gather all errors at once. Hopefully, the new 3.6.x
+        #       form handling will fix that
+        if attrtype == 'Int':
+            try:
+                value = int(value)
+            except ValueError:
+                raise ValidationError(entity.eid,
+                                      {attr: self.req._("invalid integer value")})
+        elif attrtype == 'Float':
+            try:
+                value = float(value)
+            except ValueError:
+                raise ValidationError(entity.eid,
+                                      {attr: self.req._("invalid float value")})
+        elif attrtype == 'Boolean':
             value = bool(value)
         elif attrtype == 'Decimal':
             value = Decimal(value)