当前位置: 首页>>代码示例>>Python>>正文


Python utils.flatatt方法代码示例

本文整理汇总了Python中django.forms.utils.flatatt方法的典型用法代码示例。如果您正苦于以下问题:Python utils.flatatt方法的具体用法?Python utils.flatatt怎么用?Python utils.flatatt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms.utils的用法示例。


在下文中一共展示了utils.flatatt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def render(self, name, value, attrs=None):

        date_format = "yyyy-MM-dd"

        if "format" not in self.attrs:
            attrs['format'] = date_format

        if "data-format" not in self.attrs:
            attrs['data-format'] = date_format

        field = super(DatepickerInput, self).render(name, value, attrs)
        final_attrs = self.build_attrs(attrs)

        output = format_html(u'''
         <div class="input-append date datepicker" data-provide="datepicker" {0}>
            {1}
            <span class="add-on">
                <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
            </span>
        </div>
        ''', flatatt(final_attrs), field)

        return mark_safe(output) 
开发者ID:fpsw,项目名称:Servo,代码行数:25,代码来源:base.py

示例2: render

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def render(self, name, value, attrs=None):
        if value is None:
            value = ''
        if DJANGO_11:
            final_attrs = self.build_attrs(attrs, extra_attrs={'name': name})
        else:
            final_attrs = self.build_attrs(attrs, name=name)
        final_attrs['class'] = 'nav nav-pills nav-stacked'
        output = [u'<ul%s>' % flatatt(final_attrs)]
        options = self.render_options(force_text(value), final_attrs['id'])
        if options:
            output.append(options)
        output.append(u'</ul>')
        output.append('<input type="hidden" id="%s_input" name="%s" value="%s"/>' %
                      (final_attrs['id'], name, force_text(value)))
        return mark_safe(u'\n'.join(output)) 
开发者ID:stormsha,项目名称:StormOnline,代码行数:18,代码来源:dashboard.py

示例3: render

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def render(self, name, value, attrs):
        encoded = value
        final_attrs = self.build_attrs(attrs)

        if not encoded or encoded.startswith(UNUSABLE_PASSWORD_PREFIX):
            summary = mark_safe("<strong>%s</strong>" % ugettext("No password set."))
        else:
            try:
                hasher = identify_hasher(encoded)
            except ValueError:
                summary = mark_safe("<strong>%s</strong>" % ugettext(
                    "Invalid password format or unknown hashing algorithm."))
            else:
                summary = format_html_join('',
                                           "<strong>{}</strong>: {} ",
                                           ((ugettext(key), value)
                                            for key, value in hasher.safe_summary(encoded).items())
                                           )

        return format_html("<div{}>{}</div>", flatatt(final_attrs), summary) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:forms.py

示例4: render

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def render(self, name, value, attrs=None, renderer=None):
        attrs = attrs or {}

        ace_attrs = {
            'class': 'django-ace-widget loading',
            'style': 'width:%s; height:%s' % (self.width, self.height),
            'id': 'ace_%s' % name,
        }
        if self.mode:
            ace_attrs['data-mode'] = self.mode
        if self.theme:
            ace_attrs['data-theme'] = self.theme
        if self.wordwrap:
            ace_attrs['data-wordwrap'] = 'true'

        attrs.update(style='width: 100%; min-width: 100%; max-width: 100%; resize: none')
        textarea = super(AceWidget, self).render(name, value, attrs)

        html = '<div%s><div></div></div>%s' % (flatatt(ace_attrs), textarea)

        # add toolbar
        html = ('<div class="django-ace-editor"><div style="width: 100%%" class="django-ace-toolbar">'
                '<a href="./" class="django-ace-max_min"></a></div>%s</div>') % html

        return mark_safe(html) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:27,代码来源:widgets.py

示例5: result_row_display

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def result_row_display(context, index):
    obj = context['object_list'][index]
    view = context['view']
    row_attrs_dict = view.model_admin.get_extra_attrs_for_row(obj, context)
    row_attrs_dict['data-object-pk'] = obj.pk
    odd_or_even = 'odd' if (index % 2 == 0) else 'even'
    if 'class' in row_attrs_dict:
        row_attrs_dict['class'] += ' %s' % odd_or_even
    else:
        row_attrs_dict['class'] = odd_or_even

    context.update({
        'obj': obj,
        'row_attrs': mark_safe(flatatt(row_attrs_dict)),
        'action_buttons': view.get_buttons_for_obj(obj),
    })
    return context 
开发者ID:wagtail,项目名称:wagtail,代码行数:19,代码来源:modeladmin_tags.py

示例6: admin_thumb

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def admin_thumb(self, obj):
        try:
            image = getattr(obj, self.thumb_image_field_name, None)
        except AttributeError:
            raise ImproperlyConfigured(
                u"The `thumb_image_field_name` attribute on your `%s` class "
                "must name a field on your model." % self.__class__.__name__
            )

        img_attrs = {
            'src': self.thumb_default,
            'width': self.thumb_image_width,
            'class': self.thumb_classname,
        }
        if not image:
            if self.thumb_default:
                return mark_safe('<img{}>'.format(flatatt(img_attrs)))
            return ''

        # try to get a rendition of the image to use
        from wagtail.images.shortcuts import get_rendition_or_not_found
        spec = self.thumb_image_filter_spec
        rendition = get_rendition_or_not_found(image, spec)
        img_attrs.update({'src': rendition.url})
        return mark_safe('<img{}>'.format(flatatt(img_attrs))) 
开发者ID:wagtail,项目名称:wagtail,代码行数:27,代码来源:mixins.py

示例7: mutli_render

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def mutli_render(render_func, appender_data_dict=None):
    def render(name, value=None, attrs=None, renderer=None):
        if not isinstance(value, (list, tuple)):
            value = [value]
        values = value
        widget_renderer = partial(render_func, renderer=renderer) if renderer else partial(render_func)
        # The tag is a marker for our javascript to reshuffle the elements. This is because some widgets have complex rendering with multiple fields
        pieces = ['<{tag} {multi_attr}>{widget}</{tag}>'.format(tag='div', multi_attr=config.WOOEY_MULTI_WIDGET_ATTR,
                                                                widget=widget_renderer(name, value, attrs)) for value in values]

        # we add a final piece that is our button to click for adding. It's useful to have it here instead of the template so we don't
        # have to reverse-engineer who goes with what

        # build the attribute dict
        data_attrs = flatatt(appender_data_dict if appender_data_dict is not None else {})
        pieces.append(format_html('<a href="#{anchor}"{data}><span class="glyphicon glyphicon-plus"></span></a>', anchor=config.WOOEY_MULTI_WIDGET_ANCHOR
                                  , data=data_attrs))
        return mark_safe('\n'.join(pieces))
    return render 
开发者ID:wooey,项目名称:Wooey,代码行数:21,代码来源:factory.py

示例8: attributes

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
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) 
开发者ID:salopensource,项目名称:sal,代码行数:22,代码来源:columns.py

示例9: test_flatatt

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def test_flatatt(self):
        ###########
        # flatatt #
        ###########

        self.assertEqual(flatatt({'id': "header"}), ' id="header"')
        self.assertEqual(flatatt({'class': "news", 'title': "Read this"}), ' class="news" title="Read this"')
        self.assertEqual(
            flatatt({'class': "news", 'title': "Read this", 'required': "required"}),
            ' class="news" required="required" title="Read this"'
        )
        self.assertEqual(
            flatatt({'class': "news", 'title': "Read this", 'required': True}),
            ' class="news" title="Read this" required'
        )
        self.assertEqual(
            flatatt({'class': "news", 'title': "Read this", 'required': False}),
            ' class="news" title="Read this"'
        )
        self.assertEqual(flatatt({'class': None}), '')
        self.assertEqual(flatatt({}), '') 
开发者ID:nesdis,项目名称:djongo,代码行数:23,代码来源:test_utils.py

示例10: test_flatatt_no_side_effects

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def test_flatatt_no_side_effects(self):
        """
        flatatt() does not modify the dict passed in.
        """
        attrs = {'foo': 'bar', 'true': True, 'false': False}
        attrs_copy = copy.copy(attrs)
        self.assertEqual(attrs, attrs_copy)

        first_run = flatatt(attrs)
        self.assertEqual(attrs, attrs_copy)
        self.assertEqual(first_run, ' foo="bar" true')

        second_run = flatatt(attrs)
        self.assertEqual(attrs, attrs_copy)

        self.assertEqual(first_run, second_run) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:test_utils.py

示例11: render

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def render(self, name, value, attrs=None):
        if DJANGO_11:
            final_attrs = self.build_attrs(attrs, extra_attrs={'name': name})
        else:
            final_attrs = self.build_attrs(attrs, name=name)

        output = [format_html('<select{0}>', flatatt(final_attrs))]
        if value:
            output.append(format_html('<option selected="selected" value="{0}">{1}</option>', value, self.label_for_value(value)))
        output.append('</select>')
        return mark_safe('\n'.join(output)) 
开发者ID:stormsha,项目名称:StormOnline,代码行数:13,代码来源:relfield.py

示例12: render

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
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{} />', flatatt(final_attrs)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:10,代码来源:widgets.py

示例13: tag

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def tag(self, attrs=None):
        attrs = attrs or self.attrs
        final_attrs = dict(attrs, type=self.input_type, name=self.name, value=self.choice_value)
        if self.is_checked():
            final_attrs['checked'] = 'checked'
        return format_html('<input{} />', flatatt(final_attrs)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:8,代码来源:widgets.py

示例14: label_tag

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def label_tag(self, contents=None, attrs=None, label_suffix=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.

        label_suffix allows overriding the form's label_suffix.
        """
        contents = contents or self.label
        if label_suffix is None:
            label_suffix = (self.field.label_suffix if self.field.label_suffix is not None
                            else self.form.label_suffix)
        # Only add the suffix if the label does not end in punctuation.
        # Translators: If found as last label character, these punctuation
        # characters will prevent the default label_suffix to be appended to the label
        if label_suffix and contents and contents[-1] not in _(':?.!'):
            contents = format_html('{}{}', contents, label_suffix)
        widget = self.field.widget
        id_ = widget.attrs.get('id') or self.auto_id
        if id_:
            id_for_label = widget.id_for_label(id_)
            if id_for_label:
                attrs = dict(attrs or {}, **{'for': id_for_label})
            if self.field.required and hasattr(self.form, 'required_css_class'):
                attrs = attrs or {}
                if 'class' in attrs:
                    attrs['class'] += ' ' + self.form.required_css_class
                else:
                    attrs['class'] = self.form.required_css_class
            attrs = flatatt(attrs) if attrs else ''
            contents = format_html('<label{}>{}</label>', attrs, contents)
        else:
            contents = conditional_escape(contents)
        return mark_safe(contents) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:38,代码来源:forms.py

示例15: render

# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import flatatt [as 别名]
def render(self):
        """Outputs a <ul> for this set of radio fields."""
        return format_html('<ul{}>\n{}\n</ul>',
                           flatatt(self.attrs),
                           format_html_join('\n', '<li>{}</li>',
                                            ((force_text(w),) for w in self))) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:8,代码来源:widgets.py


注:本文中的django.forms.utils.flatatt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。