本文整理汇总了Python中django.forms.util.flatatt方法的典型用法代码示例。如果您正苦于以下问题:Python util.flatatt方法的具体用法?Python util.flatatt怎么用?Python util.flatatt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.util
的用法示例。
在下文中一共展示了util.flatatt方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: label_tag
# 需要导入模块: from django.forms import util [as 别名]
# 或者: from django.forms.util import flatatt [as 别名]
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)
示例2: attributes
# 需要导入模块: from django.forms import util [as 别名]
# 或者: from django.forms.util 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)
示例3: render
# 需要导入模块: from django.forms import util [as 别名]
# 或者: from django.forms.util import flatatt [as 别名]
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,
}))
示例4: render
# 需要导入模块: from django.forms import util [as 别名]
# 或者: from django.forms.util import flatatt [as 别名]
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,
}))
示例5: render
# 需要导入模块: from django.forms import util [as 别名]
# 或者: from django.forms.util 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{0} />', flatatt(final_attrs))
示例6: tag
# 需要导入模块: from django.forms import util [as 别名]
# 或者: from django.forms.util import flatatt [as 别名]
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))
示例7: render
# 需要导入模块: from django.forms import util [as 别名]
# 或者: from django.forms.util import flatatt [as 别名]
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)