Python django.forms.util.flatatt() Examples

The following are 11 code examples of django.forms.util.flatatt(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.forms.util , or try the search function .
Example #1
Source File: forms.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def label_tag(self, contents=None, attrs=None):
        """
        Wraps the given contents in a <label>, if the field has an ID attribute.
        contents should be 'mark_safe'd to avoid HTML escaping. If contents
        aren't given, uses the field's HTML-escaped label.

        If attrs are given, they're used as HTML attributes on the <label> tag.
        """
        contents = contents or self.label
        widget = self.field.widget
        id_ = widget.attrs.get('id') or self.auto_id
        if id_:
            attrs = attrs and flatatt(attrs) or ''
            contents = format_html('<label for="{0}"{1}>{2}</label>',
                                   widget.id_for_label(id_), attrs, contents
                                   )
        else:
            contents = conditional_escape(contents)
        return mark_safe(contents) 
Example #2
Source File: columns.py    From sal with Apache License 2.0 6 votes vote down vote up
def attributes(self):
        """
        Returns a dictionary of initial state data for sorting, sort direction, and visibility.

        The default attributes include ``data-config-sortable``, ``data-config-visible``, and (if
        applicable) ``data-config-sorting`` to hold information about the initial sorting state.
        """
        attributes = {
            'data-config-sortable': 'true' if self.sortable else 'false',
            'data-config-visible': 'true' if self.visible else 'false',
        }

        if self.sort_priority is not None:
            attributes['data-config-sorting'] = ','.join(map(six.text_type, [
                self.sort_priority,
                self.index,
                self.sort_direction,
            ]))

        return flatatt(attributes) 
Example #3
Source File: widgets.py    From django-mdeditor with GNU General Public License v3.0 5 votes vote down vote up
def render(self, name, value, renderer=None, attrs=None):
        """
        renderer: django2.1 新增加的参数,此处不做应用,赋值None做兼容处理
        """
        if value is None:
            value = ''

        final_attrs = self.build_attrs(self.attrs, attrs, name=name)
        return mark_safe(render_to_string('markdown.html', {
            'final_attrs': flatatt(final_attrs),
            'value': conditional_escape(force_text(value)),
            'id': final_attrs['id'],
            'config': self.config,
        })) 
Example #4
Source File: widgets.py    From django-quill with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def render(self, name, value, attrs={}):
        """Render the Quill WYSIWYG."""
        if value is None:
            value = ''
        final_attrs = self.build_attrs(attrs, name=name)
        quill_app = apps.get_app_config('quill')
        quill_config = getattr(quill_app, self.config)

        return mark_safe(render_to_string(quill_config['template'], {
            'final_attrs': flatatt(final_attrs),
            'value': value,
            'id': final_attrs['id'],
            'config': self.config,
        })) 
Example #5
Source File: widgets.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def render(self, name, value, attrs=None):
        if value is None:
            value = ''
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
        if value != '':
            # Only add the 'value' attribute if a value is non-empty.
            final_attrs['value'] = force_text(self._format_value(value))
        return format_html('<input{0} />', flatatt(final_attrs)) 
Example #6
Source File: widgets.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def render(self, name, value, attrs=None, choices=()):
        if value is None: value = []
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
        id_ = final_attrs.get('id', None)
        inputs = []
        for i, v in enumerate(value):
            input_attrs = dict(value=force_text(v), **final_attrs)
            if id_:
                # An ID attribute was given. Add a numeric index as a suffix
                # so that the inputs don't all have the same ID attribute.
                input_attrs['id'] = '%s_%s' % (id_, i)
            inputs.append(format_html('<input{0} />', flatatt(input_attrs)))
        return mark_safe('\n'.join(inputs)) 
Example #7
Source File: widgets.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def render(self, name, value, attrs=None):
        if value is None: value = ''
        final_attrs = self.build_attrs(attrs, name=name)
        return format_html('<textarea{0}>\r\n{1}</textarea>',
                           flatatt(final_attrs),
                           force_text(value)) 
Example #8
Source File: widgets.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def render(self, name, value, attrs=None):
        final_attrs = self.build_attrs(attrs, type='checkbox', name=name)
        if self.check_test(value):
            final_attrs['checked'] = 'checked'
        if not (value is True or value is False or value is None or value == ''):
            # Only add the 'value' attribute if a value is non-empty.
            final_attrs['value'] = force_text(value)
        return format_html('<input{0} />', flatatt(final_attrs)) 
Example #9
Source File: widgets.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def render(self, name, value, attrs=None, choices=()):
        if value is None: value = ''
        final_attrs = self.build_attrs(attrs, name=name)
        output = [format_html('<select{0}>', flatatt(final_attrs))]
        options = self.render_options(choices, [value])
        if options:
            output.append(options)
        output.append('</select>')
        return mark_safe('\n'.join(output)) 
Example #10
Source File: widgets.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def tag(self):
        if 'id' in self.attrs:
            self.attrs['id'] = '%s_%s' % (self.attrs['id'], self.index)
        final_attrs = dict(self.attrs, type='radio', name=self.name, value=self.choice_value)
        if self.is_checked():
            final_attrs['checked'] = 'checked'
        return format_html('<input{0} />', flatatt(final_attrs)) 
Example #11
Source File: forms.py    From avos with Apache License 2.0 5 votes vote down vote up
def render(self, name, values, attrs=None):
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
        output = "<span id='%s'>%s</span>%s" %\
            ("id_%s_label" % name,
             "internal-db://",
             ('<input%s />' % util.flatatt(final_attrs)))
        return mark_safe(output)