web/views/editcontroller.py
branchstable
changeset 3164 b025592ff478
parent 3157 f4b94d03f86f
child 3185 bd0126d17e83
child 3194 650637d4d764
equal deleted inserted replaced
3161:005f745315b0 3164:b025592ff478
   192         attrtype = rschema.objects(entity.e_schema)[0].type
   192         attrtype = rschema.objects(entity.e_schema)[0].type
   193         # on checkbox or selection, the field may not be in params
   193         # on checkbox or selection, the field may not be in params
   194         # NOTE: raising ValidationError here is not a good solution because
   194         # NOTE: raising ValidationError here is not a good solution because
   195         #       we can't gather all errors at once. Hopefully, the new 3.6.x
   195         #       we can't gather all errors at once. Hopefully, the new 3.6.x
   196         #       form handling will fix that
   196         #       form handling will fix that
   197         if value and attrtype == 'Int':
   197         if attrtype == 'Boolean':
   198             try:
       
   199                 value = int(value)
       
   200             except ValueError:
       
   201                 raise ValidationError(entity.eid,
       
   202                                       {attr: self.req._("invalid integer value")})
       
   203         elif value and attrtype == 'Float':
       
   204             try:
       
   205                 value = float(value)
       
   206             except ValueError:
       
   207                 raise ValidationError(entity.eid,
       
   208                                       {attr: self.req._("invalid float value")})
       
   209         elif attrtype == 'Boolean':
       
   210             value = bool(value)
   198             value = bool(value)
   211         elif attrtype == 'Decimal':
   199         elif attrtype == 'Decimal':
   212             value = Decimal(value)
   200             value = Decimal(value)
   213         elif attrtype == 'Bytes':
   201         elif attrtype == 'Bytes':
   214             # if it is a file, transport it using a Binary (StringIO)
   202             # if it is a file, transport it using a Binary (StringIO)
   246                     value = val
   234                     value = val
   247             else:
   235             else:
   248                 # no specified value, skip
   236                 # no specified value, skip
   249                 return
   237                 return
   250         elif value is not None:
   238         elif value is not None:
       
   239             if attrtype == 'Int':
       
   240                 try:
       
   241                     value = int(value)
       
   242                 except ValueError:
       
   243                     raise ValidationError(entity.eid,
       
   244                                           {attr: self.req._("invalid integer value")})
       
   245             elif attrtype == 'Float':
       
   246                 try:
       
   247                     value = float(value)
       
   248                 except ValueError:
       
   249                     raise ValidationError(entity.eid,
       
   250                                           {attr: self.req._("invalid float value")})
   251             if attrtype in ('Date', 'Datetime', 'Time'):
   251             if attrtype in ('Date', 'Datetime', 'Time'):
   252                 try:
   252                 try:
   253                     value = self.parse_datetime(value, attrtype)
   253                     value = self.parse_datetime(value, attrtype)
   254                 except ValueError:
   254                 except ValueError:
   255                     raise ValidationError(entity.eid,
   255                     raise ValidationError(entity.eid,