Example #1
0
 def __call__(self, field, request):
     __traceback_info__ = (
         '{0}, processing:\n'
         '- field "{1}"\n'
         '- widget: {2}\n'
         '- params: {3}\n'.format(
             self.__class__.__name__,
             field.__name__,
             repr(self.widget_factory),
             self.params
         )
     )
     if isinstance(self.widget_factory, six.string_types):
         __traceback_info__ += '- resolving dotted name\n'
         self.widget_factory = resolveDottedName(self.widget_factory)
     if self.widget_factory is None:
         # use default widget factory for this field type
         __traceback_info__ += '- using default widget factory\n'
         widget = getMultiAdapter((field, request), IFieldWidget)
     elif IWidget.implementedBy(self.widget_factory):
         __traceback_info__ += '- calling factory, then wrapping with ' \
                               'FieldWidget\n'
         widget = FieldWidget(field, self.widget_factory(request))
     elif IFieldWidget.implementedBy(self.widget_factory):
         __traceback_info__ += '- calling factory\n'
         widget = self.widget_factory(field, request)
     for k, v in self.params.items():
         setattr(widget, k, v)
     return widget
Example #2
0
 def __init__(self, widget_factory=None, **params):
     if widget_factory is not None:
         if not IFieldWidget.implementedBy(widget_factory) \
                 and not IWidget.implementedBy(widget_factory) \
                 and not isinstance(widget_factory, six.string_types):
             raise TypeError('widget_factory must be an IFieldWidget '
                             'or an IWidget')
     self.widget_factory = widget_factory
     self.params = params
Example #3
0
 def __init__(self, widget_factory=None, **params):
     if widget_factory is not None:
         if not IFieldWidget.implementedBy(widget_factory) \
                 and not IWidget.implementedBy(widget_factory) \
                 and not isinstance(widget_factory, basestring):
             raise TypeError('widget_factory must be an IFieldWidget '
                             'or an IWidget')
     self.widget_factory = widget_factory
     self.params = params
Example #4
0
    def __call__(self, field, request):
        if isinstance(self.widget_factory, basestring):
            self.widget_factory = resolveDottedName(self.widget_factory)

        if self.widget_factory is None:
            # use default widget factory for this field type
            widget = getMultiAdapter((field, request), IFieldWidget)
        elif IWidget.implementedBy(self.widget_factory):
            widget = FieldWidget(field, self.widget_factory(request))
        elif IFieldWidget.implementedBy(self.widget_factory):
            widget = self.widget_factory(field, request)
        for k, v in self.params.items():
            setattr(widget, k, v)
        return widget
Example #5
0
    def __call__(self, field, request):
        if isinstance(self.widget_factory, basestring):
            self.widget_factory = resolveDottedName(self.widget_factory)

        if self.widget_factory is None:
            # use default widget factory for this field type
            widget = getMultiAdapter((field, request), IFieldWidget)
        elif IWidget.implementedBy(self.widget_factory):
            widget = FieldWidget(field, self.widget_factory(request))
        elif IFieldWidget.implementedBy(self.widget_factory):
            widget = self.widget_factory(field, request)
        for k, v in self.params.items():
            setattr(widget, k, v)
        return widget
Example #6
0
def reset_fileupload_widgets(form):
    for widget in form.widgets:
        if not IWidget.providedBy(widget):
            widget = form.widgets[widget]
        if INamedFileField.providedBy(widget.field):
            widget.value = None
        elif IMultiWidget.providedBy(widget):
            reset_fileupload_widgets(widget)
        elif IObjectWidget.providedBy(widget):
            reset_fileupload_widgets(widget.subform)
    try:
        for group in form.groups:
            reset_fileupload_widgets(group)
    except AttributeError:
        pass
Example #7
0
    def factory(self, field_name=None, widget_class=None, **kw):
        widgets = {}

        if field_name is None:  # Usage 3           
            for field_name, widget in kw.items():
                if not isinstance(widget, basestring):
                    widget = "%s.%s" % (widget.__module__, widget.__name__)
                widgets[field_name] = widget
        else:
            if widget_class is not None \
            and not IFieldWidget.implementedBy(widget_class) \
            and not IWidget.implementedBy(widget_class):
                raise TypeError('widget_class must implement IWidget or IFieldWidget')
            widgets[field_name] = ParameterizedWidget(widget_class, **kw)

        return widgets
Example #8
0
    def factory(self, field_name=None, widget_class=None, **kw):
        widgets = {}

        if field_name is None:  # Usage 3
            for field_name, widget in kw.items():
                if not isinstance(widget, basestring):
                    widget = "%s.%s" % (widget.__module__, widget.__name__)
                widgets[field_name] = widget
        else:
            if widget_class is not None \
               and not IFieldWidget.implementedBy(widget_class) \
               and not IWidget.implementedBy(widget_class):
                raise TypeError(
                    'widget_class must implement IWidget or IFieldWidget')
            widgets[field_name] = ParameterizedWidget(widget_class, **kw)

        return widgets
    def js(self):
        wkt_field_id = None
        if IWidget.providedBy(self.view):
            wkt_field_id = self.view.id
        elif getattr(self.view, 'widgets', None):
            wkt_field = self.view.widgets.get('wkt')
            if wkt_field:
                wkt_field_id = wkt_field.id

        if wkt_field_id:
            return """
(function ($) {
    $(window).load(function() {
        // collective geo edit map
        $('#%s').collectivegeo(
            'add_edit_layer',
            '%s'
        );
        $('#%s').collectivegeo('add_geocoder');
    });
}(jQuery));
""" % (self.mapid, wkt_field_id)
Example #10
0
 def __call__(self, field, request):
     __traceback_info__ = ('{0}, processing:\n'
                           '- field "{1}"\n'
                           '- widget: {2}\n'
                           '- params: {3}\n'.format(
                               self.__class__.__name__, field.__name__,
                               repr(self.widget_factory), self.params))
     if isinstance(self.widget_factory, six.string_types):
         __traceback_info__ += '- resolving dotted name\n'
         self.widget_factory = resolveDottedName(self.widget_factory)
     if self.widget_factory is None:
         # use default widget factory for this field type
         __traceback_info__ += '- using default widget factory\n'
         widget = getMultiAdapter((field, request), IFieldWidget)
     elif IWidget.implementedBy(self.widget_factory):
         __traceback_info__ += '- calling factory, then wrapping with ' \
                               'FieldWidget\n'
         widget = FieldWidget(field, self.widget_factory(request))
     elif IFieldWidget.implementedBy(self.widget_factory):
         __traceback_info__ += '- calling factory\n'
         widget = self.widget_factory(field, request)
     for k, v in self.params.items():
         setattr(widget, k, v)
     return widget