web/formfields.py
changeset 1889 874a055c373b
parent 1858 69e41c88e195
child 1977 606923dff11b
equal deleted inserted replaced
1888:f36d43f00f32 1889:874a055c373b
   211         # context dictionnary
   211         # context dictionnary
   212         req = form.req
   212         req = form.req
   213         try:
   213         try:
   214             return req.data[self]
   214             return req.data[self]
   215         except KeyError:
   215         except KeyError:
       
   216             fkwargs = {}
   216             if self.use_fckeditor(form):
   217             if self.use_fckeditor(form):
   217                 # if fckeditor is used and format field isn't explicitly
   218                 # if fckeditor is used and format field isn't explicitly
   218                 # deactivated, we want an hidden field for the format
   219                 # deactivated, we want an hidden field for the format
   219                 widget = HiddenInput()
   220                 fkwargs['widget'] = HiddenInput()
   220                 choices = None
   221                 fkwargs['initial'] = 'text/html'
   221             else:
   222             else:
   222                 # else we want a format selector
   223                 # else we want a format selector
   223                 # XXX compute vocabulary
   224                 fkwargs['widget'] = Select()
   224                 widget = Select()
   225                 fkwargs['widget'].attrs['size'] = 1
   225                 fcstr = FormatConstraint()
   226                 fcstr = FormatConstraint()
   226                 choices = [(req._(fmt), fmt) for fmt in fcstr.vocabulary(req=req)]
   227                 fkwargs['choices'] = fcstr.vocabulary(req=req)
   227                 widget.attrs['size'] = 1
   228                 fkwargs['internationalizable'] = True
   228             field = StringField(name=self.name + '_format', widget=widget,
   229                 fkwargs['initial'] = lambda f: f.form_field_format(self)
   229                                 choices=choices)
   230             field = StringField(name=self.name + '_format', **fkwargs)
   230             req.data[self] = field
   231             req.data[self] = field
   231             return field
   232             return field
   232 
   233 
   233     def actual_fields(self, form):
   234     def actual_fields(self, form):
   234         yield self
   235         yield self
   469             for cstr in constraints:
   470             for cstr in constraints:
   470                 if isinstance(cstr, StaticVocabularyConstraint):
   471                 if isinstance(cstr, StaticVocabularyConstraint):
   471                     kwargs.setdefault('widget', Select())
   472                     kwargs.setdefault('widget', Select())
   472                     kwargs.setdefault('choices', cstr.vocabulary)
   473                     kwargs.setdefault('choices', cstr.vocabulary)
   473                     if card in '?1':
   474                     if card in '?1':
       
   475                         if isinstance(kwargs['widget'], type):
       
   476                             kwargs['widget'] = kwargs['widget']()
   474                         kwargs['widget'].attrs.setdefault('size', 1)
   477                         kwargs['widget'].attrs.setdefault('size', 1)
       
   478             for cstr in constraints:
   475                 if isinstance(cstr, SizeConstraint) and cstr.max is not None:
   479                 if isinstance(cstr, SizeConstraint) and cstr.max is not None:
   476                     if cstr.max < 257:
   480                     if cstr.max < 257:
   477                         kwargs.setdefault('widget', TextInput())
   481                         kwargs.setdefault('widget', TextInput())
   478                     kwargs['max_length'] = cstr.max
   482                     kwargs['max_length'] = cstr.max
   479             kwargs.setdefault('widget', TextArea())
   483             kwargs.setdefault('widget', TextArea())