web/formfields.py
branchstable
changeset 9213 312062f53981
parent 9179 570208f74a84
child 9217 b4ac21bf6019
child 9278 a7894d5f00bb
equal deleted inserted replaced
9212:0d346a0a1451 9213:312062f53981
   504         """
   504         """
   505         for field in self.actual_fields(form):
   505         for field in self.actual_fields(form):
   506             if field is self:
   506             if field is self:
   507                 try:
   507                 try:
   508                     value = field.process_form_value(form)
   508                     value = field.process_form_value(form)
   509                     if value is None and field.required:
   509                     if field.no_value(value) and field.required:
   510                         raise ProcessFormError(form._cw._("required field"))
   510                         raise ProcessFormError(form._cw._("required field"))
   511                     yield field, value
   511                     yield field, value
   512                 except UnmodifiedField:
   512                 except UnmodifiedField:
   513                     continue
   513                     continue
   514             else:
   514             else:
   515                 # recursive function: we might have compound fields
   515                 # recursive function: we might have compound fields
   516                 # of compound fields (of compound fields of ...)
   516                 # of compound fields (of compound fields of ...)
   517                 for field, value in field.process_posted(form):
   517                 for field, value in field.process_posted(form):
   518                     yield field, value
   518                     yield field, value
       
   519 
       
   520     @staticmethod
       
   521     def no_value(value):
       
   522         """return True if the value can be considered as no value for the field"""
       
   523         return value is None
   519 
   524 
   520 
   525 
   521 class StringField(Field):
   526 class StringField(Field):
   522     """Use this field to edit unicode string (`String` yams type). This field
   527     """Use this field to edit unicode string (`String` yams type). This field
   523     additionaly support a `max_length` attribute that specify a maximum size for
   528     additionaly support a `max_length` attribute that specify a maximum size for
  1162                 else:
  1167                 else:
  1163                     form._cw.data['pending_others'].add( (form, self) )
  1168                     form._cw.data['pending_others'].add( (form, self) )
  1164                 return None
  1169                 return None
  1165             eids.add(typed_eid)
  1170             eids.add(typed_eid)
  1166         return eids
  1171         return eids
       
  1172 
       
  1173     @staticmethod
       
  1174     def no_value(value):
       
  1175         """return True if the value can be considered as no value for the field"""
       
  1176         # value is None is the 'not yet ready value, consider the empty set
       
  1177         return value is not None and not value
  1167 
  1178 
  1168 
  1179 
  1169 _AFF_KWARGS = uicfg.autoform_field_kwargs
  1180 _AFF_KWARGS = uicfg.autoform_field_kwargs
  1170 
  1181 
  1171 def guess_field(eschema, rschema, role='subject', req=None, **kwargs):
  1182 def guess_field(eschema, rschema, role='subject', req=None, **kwargs):