Beispiel #1
0
    def add_class_attrs(self, widget=None):
        if not widget:
            widget = self.widget

        # for multiwidgets we recursively update classes for each sub-widget
        if isinstance(widget, AdminSplitDateTime):
            for w in widget.widgets:
                self.add_class_attrs(w)
            return

        classes = widget.attrs.get('class', '')
        if isinstance(widget, ReadOnlyPasswordHashWidget):
            classes = add_css_class(classes,
                                    'form-control-static',
                                    prepend=True)
        elif isinstance(
                widget,
            (AdminDateWidget, AdminTimeWidget, RelatedFieldWidgetWrapper)):
            # for some admin widgets we don't want the input to take full horizontal space
            classes = add_css_class(classes,
                                    'form-control form-control-inline',
                                    prepend=True)
        elif not isinstance(
                widget,
            (CheckboxInput, RadioSelect, CheckboxSelectMultiple, FileInput)):
            classes = add_css_class(classes, 'form-control', prepend=True)
            # For these widget types, add the size class here
            classes = add_css_class(classes, self.get_size_class())
        widget.attrs['class'] = classes
    def add_class_attrs(self, widget=None):
        if not widget:
            widget = self.widget

        # for multiwidgets we recursively update classes for each sub-widget
        if isinstance(widget, AdminSplitDateTime):
            for w in widget.widgets:
                self.add_class_attrs(w)
            return

        classes = widget.attrs.get('class', '')
        if isinstance(widget, ReadOnlyPasswordHashWidget):
            classes = add_css_class(classes, 'form-control-static', prepend=True)
        elif isinstance(widget, (AdminDateWidget,
                                 AdminTimeWidget,
                                 RelatedFieldWidgetWrapper)):
            # for some admin widgets we don't want the input to take full horizontal space
            classes = add_css_class(classes, 'form-control form-control-inline', prepend=True)
        elif not isinstance(widget, (CheckboxInput,
                                     RadioSelect,
                                     CheckboxSelectMultiple,
                                     FileInput)):
            classes = add_css_class(classes, 'form-control', prepend=True)
            # For these widget types, add the size class here
            classes = add_css_class(classes, self.get_size_class())
        widget.attrs['class'] = classes
Beispiel #3
0
    def test_add_css_class(self):
        css_classes = "one two"
        css_class = "three four"
        classes = add_css_class(css_classes, css_class)
        self.assertEqual(classes, "one two three four")

        classes = add_css_class(css_classes, css_class, prepend=True)
        self.assertEqual(classes, "three four one two")
Beispiel #4
0
    def add_class_attrs(self, widget=None):
        super(DateTimeFieldRenderer, self).add_class_attrs(widget=widget)
        classes = widget.attrs.get('class', '')

        if isinstance(widget, DateTimeInput):  # Ora e data
            classes = add_css_class(classes, 'selettore-data-ora')

        elif isinstance(widget, DateInput):  # Solo data
            classes = add_css_class(classes, 'selettore-data')

        widget.attrs['class'] = classes
Beispiel #5
0
 def add_class_attrs(self, *args, **kwargs):
     widget = kwargs.get("widget") or self.widget
     super(AdminFieldRenderer, self).add_class_attrs(*args, **kwargs)
     if self.widget_class:
         classes = widget.attrs.get("class", "")
         classes = add_css_class(classes, self.widget_class)
         widget.attrs["class"] = classes
Beispiel #6
0
 def add_class_attrs(self, *args, **kwargs):
     widget = kwargs.get('widget') or self.widget
     super(AdminFieldRenderer, self).add_class_attrs(*args, **kwargs)
     if self.widget_class:
         classes = widget.attrs.get('class', '')
         classes = add_css_class(classes, self.widget_class)
         widget.attrs['class'] = classes
Beispiel #7
0
def render_icon(icon, **kwargs):
    """Render a Bootstrap glyphicon icon."""
    attrs = {"class": add_css_class("glyphicon glyphicon-{icon}".format(icon=icon), kwargs.get("extra_classes", ""))}
    title = kwargs.get("title")
    if title:
        attrs["title"] = title
    return render_tag("span", attrs=attrs)
 def add_class_attrs(self, *args, **kwargs):
     widget = kwargs.get('widget') or self.widget
     super(AdminFieldRenderer, self).add_class_attrs(*args, **kwargs)
     if self.widget_class:
         classes = widget.attrs.get('class', '')
         classes = add_css_class(classes, self.widget_class)
         widget.attrs['class'] = classes
Beispiel #9
0
 def get_form_group_class(self):
     form_group_class = self.form_group_class
     if self.field.errors:
         if self.error_css_class:
             form_group_class = add_css_class(form_group_class, self.error_css_class)
     else:
         if self.field.form.is_bound:
             form_group_class = add_css_class(form_group_class, self.success_css_class)
     required = (getattr(self.field.field, '_show_required', False) or getattr(self.field.field, '_required', False) or self.field.field.required)
     if required and self.required_css_class:
         form_group_class = add_css_class(form_group_class, self.required_css_class)
     if self.layout == 'horizontal':
         form_group_class = add_css_class(
             form_group_class,
             self.get_size_class(prefix='form-group')
         )
     return form_group_class
 def wrap_widget(self, html):
     if isinstance(self.widget, (CheckboxInput)):
         checkbox_class = add_css_class('checkbox checkbox-material-blue-700', self.get_size_class())
         html = '<div class="{klass}">{content}<span class="checkbox-material"><span class="check"></span></span></div>'.format(
             klass=checkbox_class,
             content=html,
         )
     return html
 def add_class_attrs(self):
     classes = self.widget.attrs.get('class', '')
     if isinstance(self.widget, ReadOnlyPasswordHashWidget):
         classes = add_css_class(classes, 'form-control-static', prepend=True)
     elif isinstance(self.widget, (AdminDateWidget,
                                   AdminTimeWidget,
                                   AdminSplitDateTime,
                                   RelatedFieldWidgetWrapper)):
         # for some admin widgets we don't want the input to take full horizontal space
         classes = add_css_class(classes, 'form-control form-control-inline', prepend=True)
     elif not isinstance(self.widget, (CheckboxInput,
                                       RadioSelect,
                                       CheckboxSelectMultiple,
                                       FileInput)):
         classes = add_css_class(classes, 'form-control', prepend=True)
         # For these widget types, add the size class here
         classes = add_css_class(classes, self.get_size_class())
     self.widget.attrs['class'] = classes
Beispiel #12
0
    def get_form_group_class(self):
        """Override adds 'group_<field_name>' class to each group."""
        form_group_class = super(ImmaterialFieldRenderer,
                                 self).get_form_group_class()

        named_group_class = 'group_{}'.format(self.field.name)

        form_group_class = add_css_class(form_group_class, named_group_class)

        return form_group_class
 def add_class_attrs(self):
     classes = self.widget.attrs.get('class', '')
     if isinstance(self.widget, ReadOnlyPasswordHashWidget):
         classes = add_css_class(classes,
                                 'form-control-static',
                                 prepend=True)
     elif isinstance(self.widget,
                     (AdminDateWidget, AdminTimeWidget, AdminSplitDateTime,
                      RelatedFieldWidgetWrapper)):
         # for some admin widgets we don't want the input to take full horizontal space
         classes = add_css_class(classes,
                                 'form-control form-control-inline',
                                 prepend=True)
     elif not isinstance(
             self.widget,
         (CheckboxInput, RadioSelect, CheckboxSelectMultiple, FileInput)):
         classes = add_css_class(classes, 'form-control', prepend=True)
         # For these widget types, add the size class here
         classes = add_css_class(classes, self.get_size_class())
     self.widget.attrs['class'] = classes
 def list_to_class(self, html, klass):
     classes = add_css_class(klass, self.get_size_class())
     mapping = [
         ('<ul', '<div'),
         ('</ul>', '</div>'),
         ('<li', '<div class="{klass} {klass}-material-blue-700"'.format(klass=classes)),
         ('</li>', '</div>'),
     ]
     for k, v in mapping:
         html = html.replace(k, v)
     return html
def render_icon(icon, **kwargs):
    """
    Render a Bootstrap glyphicon icon
    """
    attrs = {
        "class": add_css_class(
            "glyphicon glyphicon-{icon}".format(icon=icon),
            kwargs.get("extra_classes", ""),
        )
    }
    title = kwargs.get("title")
    if title:
        attrs["title"] = title
    return render_tag("span", attrs=attrs)
Beispiel #16
0
def render_icon(icon, **kwargs):
    """
    Render a Bootstrap glyphicon icon
    """
    attrs = {
        'class': add_css_class(
            'glyphicon glyphicon-{icon}'.format(icon=icon),
            kwargs.get('extra_classes', ''),
        )
    }
    title = kwargs.get('title')
    if title:
        attrs['title'] = title
    return render_tag('span', attrs=attrs)
Beispiel #17
0
def render_icon(icon, **kwargs):
    """
    Render a Bootstrap glyphicon icon
    """
    attrs = {
        'class': add_css_class(
            'glyphicon glyphicon-{icon}'.format(icon=icon),
            kwargs.get('extra_classes', ''),
        )
    }
    title = kwargs.get('title')
    if title:
        attrs['title'] = title
    return render_tag('span', attrs=attrs)
Beispiel #18
0
    def _render(self):
        """Overrides for root renderer.

        Adds helptext (append_to_field) later than usual, and adds class
        'select' when rendering a select box.
        """
        # See if we're not excluded
        if self.field.name in self.exclude.replace(' ', '').split(','):
            return ''
        # Hidden input requires no special treatment
        if self.field.is_hidden:
            return text_value(self.field)

        # Render the widget
        self.add_widget_attrs()
        if (isinstance(self.widget, Select)):
            new_classes = add_css_class(self.widget.attrs['class'], 'select')
            self.widget.attrs['class'] = new_classes

        if isinstance(self.widget, Textarea):
            self.widget.attrs['autocomplete'] = 'nope'
            # self.widget.attrs['autocorrect'] = 'off'
            # self.widget.attrs['autocapitalize'] = 'off'
            # self.widget.attrs['spellcheck'] = 'false'

            self.widget.attrs['rows'] = 6

        html = self.field.as_widget(attrs=self.widget.attrs)

        self.restore_widget_attrs()

        # Start post render
        html = self.post_widget_render(html)

        html = self.wrap_widget(html)

        html = self.make_input_group(html)

        html = self.wrap_field(html)
        html = self.add_label(html)
        html = self.append_to_field(html)
        html = self.wrap_label_and_field(html)
        return html
Beispiel #19
0
 def add_class_attrs(self):
     super(AdminFieldRenderer, self).add_class_attrs()
     if self.widget_class:
         classes = self.widget.attrs.get("class", "")
         classes = add_css_class(classes, self.widget_class)
         self.widget.attrs["class"] = classes
Beispiel #20
0
 def add_class_attrs(self):
     super(AdminFieldRenderer, self).add_class_attrs()
     if self.widget_class:
         classes = self.widget.attrs.get('class', '')
         classes = add_css_class(classes, self.widget_class)
         self.widget.attrs['class'] = classes
Beispiel #21
0
 def add_class_attrs(self):
     super(AdminFieldRenderer, self).add_class_attrs()
     if self.widget_class:
         classes = self.widget.attrs.get('class', '')
         classes = add_css_class(classes, self.widget_class)
         self.widget.attrs['class'] = classes