本文整理汇总了Python中django.utils.html.format_html_join方法的典型用法代码示例。如果您正苦于以下问题:Python html.format_html_join方法的具体用法?Python html.format_html_join怎么用?Python html.format_html_join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.html
的用法示例。
在下文中一共展示了html.format_html_join方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [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)
示例2: flatatt
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def flatatt(attrs):
"""
Convert a dictionary of attributes to a single string.
The returned string will contain a leading space followed by key="value",
XML-style pairs. In the case of a boolean value, the key will appear
without a value. It is assumed that the keys do not need to be
XML-escaped. If the passed dictionary is empty, then return an empty
string.
The result is passed through 'mark_safe' (by way of 'format_html_join').
"""
key_value_attrs = []
boolean_attrs = []
for attr, value in attrs.items():
if isinstance(value, bool):
if value:
boolean_attrs.append((attr,))
elif value is not None:
key_value_attrs.append((attr, value))
return (
format_html_join('', ' {}="{}"', sorted(key_value_attrs)) +
format_html_join('', ' {}', sorted(boolean_attrs))
)
示例3: editor_js
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def editor_js():
# Add extra JS files to the admin
js_files = [
'js/hallo-custom.js',
]
js_includes = format_html_join(
'\n', '<script src="{0}{1}"></script>',
((settings.STATIC_URL, filename) for filename in js_files)
)
return js_includes + format_html(
"""
<script>
registerHalloPlugin('blockquotebutton');
registerHalloPlugin('blockquotebuttonwithclass');
</script>
"""
)
示例4: validation_error
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def validation_error(request, message, form, buttons=None):
if not form.non_field_errors():
# just output the generic "there were validation errors" message, and leave
# the per-field highlighting to do the rest
detail = ''
else:
# display the full list of field and non-field validation errors
all_errors = []
for field_name, errors in form.errors.items():
if field_name == NON_FIELD_ERRORS:
prefix = ''
else:
try:
field_label = form[field_name].label
except KeyError:
field_label = field_name
prefix = "%s: " % field_label
for error in errors:
all_errors.append(prefix + error)
errors_html = format_html_join('\n', '<li>{}</li>', ((e,) for e in all_errors))
detail = format_html("""<ul class="errorlist">{}</ul>""", errors_html)
return messages.error(request, render(message, buttons, detail=detail))
示例5: flatatt
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def flatatt(attrs):
"""
Convert a dictionary of attributes to a single string.
The returned string will contain a leading space followed by key="value",
XML-style pairs. In the case of a boolean value, the key will appear
without a value. It is assumed that the keys do not need to be
XML-escaped. If the passed dictionary is empty, then return an empty
string.
The result is passed through 'mark_safe' (by way of 'format_html_join').
"""
key_value_attrs = []
boolean_attrs = []
for attr, value in attrs.items():
if isinstance(value, bool):
if value:
boolean_attrs.append((attr,))
else:
key_value_attrs.append((attr, value))
return (
format_html_join('', ' {}="{}"', sorted(key_value_attrs)) +
format_html_join('', ' {}', sorted(boolean_attrs))
)
示例6: insert_editor_js
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def insert_editor_js():
js_files = [
# We require this file here to make sure it is loaded before the other.
'wagtailadmin/js/draftail.js',
'colourpicker/js/colourpicker.js',
]
js_includes = format_html_join(
'\n',
'<script src="{0}"></script>',
((static(filename), ) for filename in js_files)
)
js_includes += format_html(
"<script>window.chooserUrls.colourChooser = '{0}';</script>",
reverse('wagtailcolourpicker:chooser')
)
return js_includes
示例7: _render_readonly
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def _render_readonly(self, name, value, attrs=None, renderer=None, request=None, form=None, initial_value=None):
if request and value and isinstance(value, (list, tuple)):
rendered_values = []
for value_item in value:
choice = self._choice(value_item)
if choice:
value_item = force_text(choice[1])
if choice.obj:
rendered_values.append(self._render_object(request, choice.obj, value_item))
else:
rendered_values.append(value_item)
return format_html(
'<p>{}</p>',
format_html_join(', ', '{}', ((v,) for v in rendered_values)) if rendered_values else EMPTY_VALUE
)
else:
return super(ModelObjectReadonlyWidget, self)._render_readonly(
name, value, attrs, renderer, request, form, initial_value
)
示例8: editor_js
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def editor_js():
js_files = [
'js/contact_person_slug.js',
]
js_includes = format_html_join('\n', '<script src="{0}{1}"></script>',
((settings.STATIC_URL, filename)
for filename in js_files)
)
return js_includes
示例9: as_ul
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def as_ul(self):
if not self:
return ''
return format_html(
'<ul class="errorlist">{}</ul>',
format_html_join('', '<li>{}{}</li>', self.items())
)
示例10: editor_css
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def editor_css():
# Add extra CSS files to the admin like font-awesome
css_files = [
'node_modules/font-awesome/css/font-awesome.min.css'
]
css_includes = format_html_join(
'\n', '<link rel="stylesheet" href="{0}{1}">',
((settings.STATIC_URL, filename) for filename in css_files)
)
return css_includes
示例11: include_regexps_
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def include_regexps_(obj):
return format_html_join('\n', '<pre>{}</pre>',
((r,) for r in
obj.include_regexps.split('\n'))) if obj.field and obj.include_regexps else None
示例12: exclude_regexps_
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def exclude_regexps_(obj: DocumentFieldDetector):
return format_html_join('\n', '<pre>{}</pre>',
((r,) for r in
obj.exclude_regexps.split('\n'))) if obj.field and obj.exclude_regexps else None
示例13: definition_words_
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def definition_words_(obj: DocumentFieldDetector):
return format_html_join('\n', '<pre>{}</pre>',
((r,) for r in
obj.definition_words.split('\n'))) if obj.field and obj.definition_words else None
示例14: _password_validators_help_text_html
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def _password_validators_help_text_html(password_validators=None):
"""
Return an HTML string with all help texts of all configured validators
in an <ul>.
"""
help_texts = password_validators_help_texts(password_validators)
help_items = format_html_join('', '<li>{}</li>', ((help_text,) for help_text in help_texts))
return format_html('<ul>{}</ul>', help_items) if help_items else ''
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:10,代码来源:password_validation.py
示例15: htmlvalue
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html_join [as 别名]
def htmlvalue(self, val):
htmlvalues = []
for name, block in self.block.child_blocks.items():
label = self.block.child_blocks[name].label
comparison_class = get_comparison_class_for_block(block)
htmlvalues.append((label, comparison_class(block, True, True, val[name], val[name]).htmlvalue(val[name])))
return format_html('<dl>\n{}\n</dl>', format_html_join(
'\n', ' <dt>{}</dt>\n <dd>{}</dd>', htmlvalues))