當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。