本文整理汇总了Python中django.utils.html.format_html方法的典型用法代码示例。如果您正苦于以下问题:Python html.format_html方法的具体用法?Python html.format_html怎么用?Python html.format_html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.html
的用法示例。
在下文中一共展示了html.format_html方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [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)
示例2: render_option
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def render_option(self, selected_choices, option_value, option_label):
if option_value is None:
option_value = ''
option_value = force_text(option_value)
if option_value in selected_choices:
selected_html = mark_safe(' selected="selected"')
if not self.allow_multiple_selected:
# Only allow for a single selection.
selected_choices.remove(option_value)
else:
selected_html = ''
return format_html('<option data-icon="{0}" value="{0}"{1}>{2}</option>',
option_value,
selected_html,
force_text(option_label),
)
示例3: last_beat_column
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def last_beat_column(self, object):
last_beat = object.last_beat
if is_aware(last_beat):
# Only for USE_TZ=True
last_beat = localtime(last_beat)
last_beat_str = localize(last_beat)
if object.is_expired:
# Make clearly visible
alert_icon = static('admin/img/icon-alert.svg')
return format_html(
'<div style="vertical-align: middle; display: inline-block;">'
' <img src="{}" style="vertical-align: middle;"> '
' <span style="color: #efb80b; vertical-align: middle;">{}</span>'
'</div>',
alert_icon, last_beat_str
)
else:
return last_beat_str
示例4: build_attrs
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def build_attrs(self, attrs={}, extra_attrs=None, **kwargs):
to_opts = self.rel.to._meta
if "class" not in attrs:
attrs['class'] = 'select-search'
else:
attrs['class'] = attrs['class'] + ' select-search'
attrs['data-search-url'] = self.admin_view.get_admin_url(
'%s_%s_changelist' % (to_opts.app_label, to_opts.model_name))
attrs['data-placeholder'] = _('Search %s') % to_opts.verbose_name
attrs['data-choices'] = '?'
if self.rel.limit_choices_to:
for i in list(self.rel.limit_choices_to):
attrs['data-choices'] += "&_p_%s=%s" % (i, self.rel.limit_choices_to[i])
attrs['data-choices'] = format_html(attrs['data-choices'])
if DJANGO_11:
attrs.update(kwargs)
return super(ForeignKeySearchWidget, self).build_attrs(attrs, extra_attrs=extra_attrs)
else:
if extra_attrs:
attrs.update(extra_attrs)
return super(ForeignKeySearchWidget, self).build_attrs(attrs, **kwargs)
示例5: display_for_field
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def display_for_field(value, field):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
if field.flatchoices:
return dict(field.flatchoices).get(value, EMPTY_CHANGELIST_VALUE)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return _boolean_icon(value)
elif value is None:
return EMPTY_CHANGELIST_VALUE
elif isinstance(field, models.DateTimeField):
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return smart_text(value)
示例6: user_link
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def user_link(self, obj):
if obj.user:
return format_html(
'<a href="{}">{}</a>',
reverse("admin:auth_user_change", args=(obj.user.pk,)),
obj.user.email)
else:
return 'no user in this record'
示例7: as_html
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def as_html(self):
if not self.id:
return ''
prefix = getattr(settings, 'FONTAWESOME_PREFIX', 'fa')
return format_html('<i class="{0} {0}-{1}"></i>', prefix, self.id)
示例8: fontawesome_stylesheet
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def fontawesome_stylesheet():
href = getattr(settings, 'FONTAWESOME_CSS_URL', static('fontawesome/css/font-awesome.min.css'))
link = format_html('<link href="{0}" rel="stylesheet" media="all">', href)
return link
示例9: render
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def render(self, name, value, attrs=None, renderer=None):
return format_html(
"""
<div class="mf_widget mf_model_{0}">
<input id="id_{1}" name="{1}" class="mf_selection" type="hidden" value="{2}"/>
<label class="mf_groupingLabel">Group:</label> <select class="mf_grouping"></select>
<label class="mf_filterLabel">Filter:</label> <input class="mf_filter" type="text"/> <br />
<select size="6" class="mf_selectbox"></select> <br />
<span class="mf_description" /> </div>""",
self.model,
name,
value,
)
示例10: sortlink
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def sortlink(style, contents, **args):
return format_html(
'<a href="?{args}"{style}><span style="display:none;">{contents}</span></a>',
args=urllib.parse.urlencode([a for a in list(args.items()) if a[1]]),
style=format_html(' class="{style}"', style=style) if style else '',
contents=contents,
)
示例11: render
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def render(self, name, value, attrs=None, renderer=None):
substitutions = {
'initial_text': self.initial_text,
'input_text': self.input_text,
}
template = '%(input)s'
substitutions['input'] = super(NotClearableFileInput, self).render(name, value, attrs=attrs, renderer=renderer)
if value:
template = self.template_with_initial
substitutions['initial'] = format_html(force_text(os.path.basename(value.name)))
return mark_safe(template % substitutions)
示例12: __init__
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def __init__(self, field, request, params, model, model_admin, field_path):
other_model = get_model_from_relation(field)
if hasattr(field, 'rel'):
rel_name = field.rel.get_related_field().name
else:
rel_name = other_model._meta.pk.name
self.lookup_formats = {'in': '%%s__%s__in' % rel_name,'exact': '%%s__%s__exact' % rel_name}
super(RelatedFieldSearchFilter, self).__init__(
field, request, params, model, model_admin, field_path)
related_modeladmin = self.admin_view.admin_site._registry.get(other_model)
self.relfield_style = related_modeladmin.relfield_style
if hasattr(field, 'verbose_name'):
self.lookup_title = field.verbose_name
else:
self.lookup_title = other_model._meta.verbose_name
self.title = self.lookup_title
self.search_url = model_admin.get_admin_url('%s_%s_changelist' % (
other_model._meta.app_label, other_model._meta.model_name))
self.label = self.label_for_value(other_model, rel_name, self.lookup_exact_val) if self.lookup_exact_val else ""
self.choices = '?'
if field.rel.limit_choices_to:
for i in list(field.rel.limit_choices_to):
self.choices += "&_p_%s=%s" % (i, field.rel.limit_choices_to[i])
self.choices = format_html(self.choices)
示例13: render
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [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))
示例14: game_link_url
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def game_link_url(self, obj):
if not obj.game_link:
return ''
return format_html("<a href='{url}'>{url}</a>", url=obj.game_link)
示例15: add_article
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def add_article(self, obj):
url_name = "wagtailadmin_pages:add_subpage"
url = reverse(url_name, args=[obj.id])
return format_html(
f'<a href="{url}" class="button button-small button-secondary">Add Article</a>'
)