예제 #1
0
    def get_context(self, name, value, attrs):
        # We bypass the ChoiceWidget context to avoid `optgroups` from
        # being called, as the choices format is not compatible with it.
        context = Widget.get_context(self, name, value, attrs)

        context["widget"]["flat_tree"] = self.flat_tree(
            name, context["widget"]["value"], attrs)
        context["widget"]["columns_classes"] = self.columns_classes
        context["widget"]["container_classes"] = self.container_classes

        return context
예제 #2
0
    def __init__(self, field_to_send, attrs=None, choices=()):
        """
        Initializes parent classes BootstrapTable and Widget and sets some
        variables to allow imitating Select widget with use of BootstrapTable.

        Args:

        field_to_send: name of field, from which value will be send to server,
        when submitting your form.

        attrs: standard Django's attributes, to pass into Widget initializer.

        choices: iterable with options available to choose (rows' contents).
        """
        BootstrapTable.__init__(self)
        Widget.__init__(self, attrs)
        self._choices = None
        self.choices = list(choices)
        self.set(clickToSelect=True)
        self.set(idField=field_to_send)
예제 #3
0
    def get_context(self, name, value, attrs):
        # Do not call ChoiceWidget.get_context() as it would try to serialize the whole fk queryset, which may be huge.
        context = Widget.get_context(self, name, value, attrs)
        widget_ctx = context['widget']
        remove_css_classes_from_dict(widget_ctx['attrs'], 'form-control')
        widget_ctx['attrs']['type'] = 'hidden'
        widget_ctx['value'] = value

        # Autodetect foreign key widgets fkGridOptions.
        ContextMiddleware = apps.DjkAppConfig.get_context_middleware()
        self.request = ContextMiddleware.get_request()
        widget_view = resolve_grid(
            request=self.request,
            view_options=self.component_options['fkGridOptions'])()
        foreign_key_grid_options = widget_view.discover_grid_options(
            self.request, self.component_options['fkGridOptions'])
        foreign_key_grid_options[
            'selectMultipleRows'] = self.allow_multiple_selected
        widget_view.setup(self.request, **self.get_widget_view_kwargs())
        foreign_key_grid_options['pkField'] = widget_view.pk_field

        if value is None:
            initial_fk_rows = []
        else:
            if isinstance(value, (QuerySet, RawQuerySet, ListQuerySet)):
                fk_qs = value
            else:
                fk_qs = self.get_initial_fk_grid_queryset(widget_view, value)
            initial_fk_rows = widget_view.postprocess_qs(fk_qs)

        self.component_options.update({
            'attrs':
            widget_ctx['attrs'],
            'isRequired':
            widget_ctx['required'] if self.required is None else self.required,
            'initialFkRows':
            initial_fk_rows,
            'clickActions':
            widget_view.vm_get_actions('click'),
            'name':
            name,
        })

        # Update widget grid_options with recursively detected fkGridOptions, if any.
        sdv.nested_update(self.component_options['fkGridOptions'],
                          foreign_key_grid_options)
        widget_ctx['component_attrs'] = self.get_component_attrs()
        return context
예제 #4
0
def _add_class(widget: Widget, cls: str) -> None:
    if cls is not None:
        try:
            widget.attrs["class"] += cls
        except KeyError:
            widget.attrs["class"] = cls + " "
예제 #5
0
파일: widgets.py 프로젝트: gauravjana/Form
 def __init__(self, attrs=None, choices=()):
     # skip choice initialization in widgets.ChoiceWidget.__init__
     Widget.__init__(self, attrs)
     self.choices = choices
예제 #6
0
 def runTest(self):
     widget = Widget("The widget")
     assert widget.size() == (50, 50), 'incorrect default size'
예제 #7
0
	def build_attrs(self, extra_attrs={}, name='', **kwargs):
		name = extra_attrs.get('name', name)
		extra_attrs['id'] = extra_attrs.get('id', 'id_'+name)
		return Widget.build_attrs(self, extra_attrs, **kwargs)
예제 #8
0
 def __init__(self, selectedValue='1'):
     Widget.__init__(self)
     self.selectedValue = selectedValue
예제 #9
0
	def build_attrs(self, extra_attrs={}, name='', **kwargs):
		name = extra_attrs.get('name', name)
		extra_attrs['id'] = extra_attrs.get('id', 'id_'+name)
		return Widget.build_attrs(self, extra_attrs, **kwargs)