Exemplo n.º 1
0
 def get_format_field(self, form):
     if self.format_field:
         return self.format_field
     # we have to cache generated field since it's use as key in the
     # context dictionary
     req = form._cw
     try:
         return req.data[self]
     except KeyError:
         fkwargs = {'eidparam': self.eidparam, 'role': self.role}
         if self.use_fckeditor(form):
             # if fckeditor is used and format field isn't explicitly
             # deactivated, we want an hidden field for the format
             fkwargs['widget'] = fw.HiddenInput()
             fkwargs['value'] = 'text/html'
         else:
             # else we want a format selector
             fkwargs['widget'] = fw.Select()
             fcstr = FormatConstraint()
             fkwargs['choices'] = fcstr.vocabulary(form=form)
             fkwargs['internationalizable'] = True
             fkwargs['value'] = self.format
         fkwargs['eidparam'] = self.eidparam
         field = StringField(name=self.name + '_format', **fkwargs)
         req.data[self] = field
         return field
Exemplo n.º 2
0
 def init_widget(self, widget):
     if widget is not None:
         self.widget = widget
     elif self.choices and not self.widget.vocabulary_widget:
         self.widget = fw.Select()
     if isinstance(self.widget, type):
         self.widget = self.widget()
Exemplo n.º 3
0
    def init_widget(self, widget):
        if widget is None:
            if self.choices:
                widget = fw.Select()
            elif self.max_length and self.max_length < 257:
                widget = fw.TextInput()

        super(StringField, self).init_widget(widget)
        if isinstance(self.widget, fw.TextArea):
            self.init_text_area(self.widget)
        elif isinstance(self.widget, fw.TextInput):
            self.init_text_input(self.widget)

        if self.placeholder:
            self.widget.attrs.setdefault('placeholder', self.placeholder)
Exemplo n.º 4
0
 def fromcardinality(cls, card, **kwargs):
     kwargs.setdefault('widget', fw.Select(multiple=card in '*+'))
     return cls(**kwargs)
Exemplo n.º 5
0
# the CEA-CNRS-INRIA. Refer to the LICENSE file or to
# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
# for details.
##########################################################################

from cubicweb.web import formwidgets as fwdgs
from cubicweb.web.views import uicfg
from cubicweb.web.views.uicfg import autoform_field_kwargs as affk
from cwsearch import CWSearchPathWidget

uicfg.autoform_section.hide_fields("CWSearch", ("rset", "result",
                                                "expiration_date", "rset_type",
                                                ))


def rset_type_choices(form, field, **kw):
    res = set()
    for vid, views in form._cw.vreg["views"].iteritems():
        for v in views:
            if not v.templatable and v.binary:
                res.add(v.__regid__)
    return list(res)


affk.set_field_kwargs("CWSearch", "rset_type",
                      widget=fwdgs.Select(),
                      choices=("jsonexport", ))
                      #choices=rset_type_choices)
affk.set_field_kwargs("CWSearch", "path",
                      widget=CWSearchPathWidget)