cubicweb/web/formfields.py
changeset 11910 af969080e7e6
parent 11870 3a84a79c4ed5
child 11929 fcbd6b251d81
equal deleted inserted replaced
11900:8496135b6dc1 11910:af969080e7e6
  1233         kwargs.setdefault('label', (eschema.type, rschema.type + '_object'))
  1233         kwargs.setdefault('label', (eschema.type, rschema.type + '_object'))
  1234     else:
  1234     else:
  1235         kwargs.setdefault('label', (eschema.type, rschema.type))
  1235         kwargs.setdefault('label', (eschema.type, rschema.type))
  1236     kwargs.setdefault('help', rdef.description)
  1236     kwargs.setdefault('help', rdef.description)
  1237     if rschema.final:
  1237     if rschema.final:
  1238         fieldclass = FIELDS[targetschema]
  1238         fieldclass = kwargs.pop('fieldclass', FIELDS[targetschema])
  1239         if fieldclass is StringField:
  1239         if issubclass(fieldclass, FileField):
       
  1240             if req:
       
  1241                 aff_kwargs = req.vreg['uicfg'].select('autoform_field_kwargs', req)
       
  1242             else:
       
  1243                 aff_kwargs = _AFF_KWARGS
       
  1244             for metadata in KNOWN_METAATTRIBUTES:
       
  1245                 metaschema = eschema.has_metadata(rschema, metadata)
       
  1246                 if metaschema is not None:
       
  1247                     metakwargs = aff_kwargs.etype_get(eschema, metaschema, 'subject')
       
  1248                     kwargs['%s_field' % metadata] = guess_field(eschema, metaschema,
       
  1249                                                                 req=req, **metakwargs)
       
  1250         elif issubclass(fieldclass, StringField):
  1240             if eschema.has_metadata(rschema, 'format'):
  1251             if eschema.has_metadata(rschema, 'format'):
  1241                 # use RichTextField instead of StringField if the attribute has
  1252                 # use RichTextField instead of StringField if the attribute has
  1242                 # a "format" metadata. But getting information from constraints
  1253                 # a "format" metadata. But getting information from constraints
  1243                 # may be useful anyway...
  1254                 # may be useful anyway...
  1244                 for cstr in rdef.constraints:
  1255                 for cstr in rdef.constraints:
  1251                     kwargs.setdefault('choices', cstr.vocabulary)
  1262                     kwargs.setdefault('choices', cstr.vocabulary)
  1252                     break
  1263                     break
  1253             for cstr in rdef.constraints:
  1264             for cstr in rdef.constraints:
  1254                 if isinstance(cstr, SizeConstraint) and cstr.max is not None:
  1265                 if isinstance(cstr, SizeConstraint) and cstr.max is not None:
  1255                     kwargs['max_length'] = cstr.max
  1266                     kwargs['max_length'] = cstr.max
  1256             return StringField(**kwargs)
       
  1257         if fieldclass is FileField:
       
  1258             if req:
       
  1259                 aff_kwargs = req.vreg['uicfg'].select('autoform_field_kwargs', req)
       
  1260             else:
       
  1261                 aff_kwargs = _AFF_KWARGS
       
  1262             for metadata in KNOWN_METAATTRIBUTES:
       
  1263                 metaschema = eschema.has_metadata(rschema, metadata)
       
  1264                 if metaschema is not None:
       
  1265                     metakwargs = aff_kwargs.etype_get(eschema, metaschema, 'subject')
       
  1266                     kwargs['%s_field' % metadata] = guess_field(eschema, metaschema,
       
  1267                                                                 req=req, **metakwargs)
       
  1268         return fieldclass(**kwargs)
  1267         return fieldclass(**kwargs)
  1269     return RelationField.fromcardinality(card, **kwargs)
  1268     return RelationField.fromcardinality(card, **kwargs)
  1270 
  1269 
  1271 
  1270 
  1272 FIELDS = {
  1271 FIELDS = {