[edition] convert integer and float values coming from edit forms so that values are correctly typed in before_xxx hooks
--- 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)