web/formfields.py
branchtls-sprint
changeset 1147 402e8a8b1d6a
parent 1108 1e5ed5f57f2f
child 1181 620ec8e6ae19
equal deleted inserted replaced
1146:547681592765 1147:402e8a8b1d6a
   305     @staticmethod
   305     @staticmethod
   306     def fromcardinality(card, **kwargs):
   306     def fromcardinality(card, **kwargs):
   307         return RelationField(widget=Select(multiple=card in '*+'), **kwargs)
   307         return RelationField(widget=Select(multiple=card in '*+'), **kwargs)
   308         
   308         
   309     def vocabulary(self, form):
   309     def vocabulary(self, form):
   310         entity = form.entity
   310         entity = form.edited_entity
   311         req = entity.req
   311         req = entity.req
   312         # first see if its specified by __linkto form parameters
   312         # first see if its specified by __linkto form parameters
   313         linkedto = entity.linked_to(self.name, self.role)
   313         linkedto = entity.linked_to(self.name, self.role)
   314         if linkedto:
   314         if linkedto:
   315             entities = (req.eid_rset(eid).get_entity(0, 0) for eid in linkedto)
   315             entities = (req.eid_rset(eid).get_entity(0, 0) for eid in linkedto)
   332 
   332 
   333 def stringfield_from_constraints(constraints, **kwargs):
   333 def stringfield_from_constraints(constraints, **kwargs):
   334     field = None
   334     field = None
   335     for cstr in constraints:
   335     for cstr in constraints:
   336         if isinstance(cstr, StaticVocabularyConstraint):
   336         if isinstance(cstr, StaticVocabularyConstraint):
   337             return StringField(widget=Select(vocabulary=cstr.vocabulary),
   337             kwargs.setdefault('widget', Select(vocabulary=cstr.vocabulary))
   338                                **kwargs)
   338             return StringField(**kwargs)
   339         if isinstance(cstr, SizeConstraint) and cstr.max is not None:
   339         if isinstance(cstr, SizeConstraint) and cstr.max is not None:
   340             if cstr.max > 257:
   340             if cstr.max > 257:
   341                 rows_cols_from_constraint(cstr, kwargs)
   341                 rows_cols_from_constraint(cstr, kwargs)
   342                 field = TextField(**kwargs)
   342                 field = TextField(**kwargs)
   343             else:
   343             else:
   373             return None
   373             return None
   374         fieldclass = FIELDS[targetschema]
   374         fieldclass = FIELDS[targetschema]
   375         if fieldclass is StringField:
   375         if fieldclass is StringField:
   376             if targetschema == 'Password':
   376             if targetschema == 'Password':
   377                 # special case for Password field: specific PasswordInput widget
   377                 # special case for Password field: specific PasswordInput widget
   378                 return StringField(widget=PasswordInput(), **kwargs)
   378                 kwargs.setdefault('widget', PasswordInput())
       
   379                 return StringField(**kwargs)
   379             if eschema.has_metadata(rschema, 'format'):
   380             if eschema.has_metadata(rschema, 'format'):
   380                 # use RichTextField instead of StringField if the attribute has
   381                 # use RichTextField instead of StringField if the attribute has
   381                 # a "format" metadata. But getting information from constraints
   382                 # a "format" metadata. But getting information from constraints
   382                 # may be useful anyway...
   383                 # may be useful anyway...
   383                 constraints = rschema.rproperty(eschema, targetschema, 'constraints')
   384                 constraints = rschema.rproperty(eschema, targetschema, 'constraints')