本文整理汇总了Python中django.utils.html.format_html方法的典型用法代码示例。如果您正苦于以下问题:Python html.format_html方法的具体用法?Python html.format_html怎么用?Python html.format_html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块django.utils.html的用法示例。
在下文中一共展示了html.format_html方法的25个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: render
点赞 6
# 需要导入模块: 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'''
{1}
''', flatatt(final_attrs), field)
return mark_safe(output)
开发者ID:fpsw,项目名称:Servo,代码行数:25,
示例2: render_option
点赞 6
# 需要导入模块: 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('{2}',
option_value,
selected_html,
force_text(option_label),
)
开发者ID:redouane,项目名称:django-fontawesome,代码行数:18,
示例3: last_beat_column
点赞 6
# 需要导入模块: 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(
'
' '
' {}'
'
alert_icon, last_beat_str
)
else:
return last_beat_str
开发者ID:mvantellingen,项目名称:django-healthchecks,代码行数:21,
示例4: build_attrs
点赞 6
# 需要导入模块: 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)
开发者ID:stormsha,项目名称:StormOnline,代码行数:23,
示例5: display_for_field
点赞 6
# 需要导入模块: 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('{}', value.url, value)
else:
return smart_text(value)
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:26,
示例6: user_link
点赞 5
# 需要导入模块: 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(
'{}',
reverse("admin:auth_user_change", args=(obj.user.pk,)),
obj.user.email)
else:
return 'no user in this record'
开发者ID:appsembler,项目名称:figures,代码行数:10,
示例7: as_html
点赞 5
# 需要导入模块: 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('', prefix, self.id)
开发者ID:redouane,项目名称:django-fontawesome,代码行数:8,
示例8: fontawesome_stylesheet
点赞 5
# 需要导入模块: 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('', href)
return link
开发者ID:redouane,项目名称:django-fontawesome,代码行数:6,
示例9: render
点赞 5
# 需要导入模块: 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(
"""
""",self.model,
name,
value,
)
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:15,
示例10: sortlink
点赞 5
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def sortlink(style, contents, **args):
return format_html(
'{contents}',
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,
)
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:9,
示例11: render
点赞 5
# 需要导入模块: 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)
开发者ID:sfu-fas,项目名称:coursys,代码行数:15,
示例12: __init__
点赞 5
# 需要导入模块: 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)
开发者ID:stormsha,项目名称:StormOnline,代码行数:29,
示例13: render
点赞 5
# 需要导入模块: 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('', flatatt(final_attrs))]
if value:
output.append(format_html('{1}', value, self.label_for_value(value)))
output.append('')
return mark_safe('\n'.join(output))
开发者ID:stormsha,项目名称:StormOnline,代码行数:13,
示例14: game_link_url
点赞 5
# 需要导入模块: 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("{url}", url=obj.game_link)
开发者ID:cyanfish,项目名称:heltour,代码行数:6,
示例15: add_article
点赞 5
# 需要导入模块: 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'Add Article'
)
开发者ID:WesternFriend,项目名称:WF-website,代码行数:9,
示例16: view_articles
点赞 5
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def view_articles(self, obj):
url_name = "wagtailadmin_explore"
url = reverse(url_name, args=[obj.id])
return format_html(
)
开发者ID:WesternFriend,项目名称:WF-website,代码行数:9,
示例17: post
点赞 5
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def post(self, request, *args, **kwargs):
action = request.POST.get('action')
mode = request.POST.get('mode')
index = request.POST.getlist('index')
objects = self.get_queryset().filter(pk__in=index)
if mode == 'all':
objects = self.get_queryset()
redirect_to = reverse_lazy('idcops:list', args=[self.model_name])
if action == 'config':
postdata = request.POST.copy()
self.user_config(postdata)
return HttpResponseRedirect(redirect_to)
if not objects.exists() and action != 'config':
messages.warning(request, "您必须选中一些条目")
else:
try:
current_action = import_string(
'idcops.actions.{}'.format(action))
description = current_action.description
metric = getattr(self.opts, 'metric', "条")
mesg = format_html(
'您一共 {0} 了 {1} {2} {3}'.format(
description, objects.count(), metric, self.opts.verbose_name)
)
result = current_action(request, objects)
# error has message.
if isinstance(result, six.string_types):
# if isinstance(result, (unicode, str)):
messages.warning(request, result)
redirect_to = redirect_to + self.get_query_string()
return HttpResponseRedirect(redirect_to)
elif result:
return result
else:
messages.success(request, mesg)
return HttpResponseRedirect(redirect_to)
except Exception as e:
messages.warning(request, 'unknown your action: {}'.format(e))
return HttpResponseRedirect(redirect_to)
开发者ID:Wenvki,项目名称:django-idcops,代码行数:41,
示例18: make_boolean_icon
点赞 5
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def make_boolean_icon(field_val):
choice = {
True: 'fa fa-check-circle text-green',
False: 'fa fa-ban on fa-check-circle text-red',
None: 'unknown'}[field_val]
return format_html(''.format(choice))
开发者ID:Wenvki,项目名称:django-idcops,代码行数:8,
示例19: make_color_icon
点赞 5
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def make_color_icon(field_val):
return format_html('
开发者ID:Wenvki,项目名称:django-idcops,代码行数:4,
示例20: display_for_field
点赞 5
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def display_for_field(value, field, html=True, only_date=True):
if getattr(field, 'flatchoices', None):
if html and field.name == 'color' and value:
return make_color_icon(value)
return dict(field.flatchoices).get(value, '')
elif html and (isinstance(field, (models.BooleanField, models.NullBooleanField))):
return make_boolean_icon(value)
elif isinstance(field, (models.BooleanField, models.NullBooleanField)):
boolchoice = {False: "否", True: "是"}
return boolchoice.get(value)
elif value is None:
return ""
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.ForeignKey) and value:
rel_obj = field.related_model.objects.get(pk=value)
if html and COLOR_FK_FIELD and isinstance(rel_obj, Option):
text_color = rel_obj.color
if not text_color:
text_color = 'text-info'
safe_value = format_html(
'{}', text_color, rel_obj.text)
return safe_value
return force_text(rel_obj)
elif isinstance(field, models.TextField) and value:
return force_text(value)
elif isinstance(field, models.DateTimeField):
if only_date:
return formats.date_format(value)
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.FileField) and value:
return format_html('{}', value.url, value)
else:
return display_for_value(value)
开发者ID:Wenvki,项目名称:django-idcops,代码行数:40,
示例21: image_thumbnail
点赞 5
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def image_thumbnail(self, obj):
if obj.image:
return format_html('', obj.image.url)
return ''
开发者ID:ulule,项目名称:django-badgify,代码行数:6,
示例22: link
点赞 5
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def link(self, obj):
return format_html('{1}',
self.view_on_site(obj),
self.view_on_site(obj))
开发者ID:ulule,项目名称:django-badgify,代码行数:6,
示例23: render_js
点赞 5
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def render_js(self):
return [
format_html(
'',
self.absolute_path(path)
) for path in self._js
]
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:9,
示例24: render_css
点赞 5
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [as 别名]
def render_css(self):
# To keep rendering order consistent, we can't just iterate over items().
# We need to sort the keys, and iterate over the sorted list.
media = sorted(self._css.keys())
return chain(*[[
format_html(
'',
self.absolute_path(path), medium
) for path in self._css[medium]
] for medium in media])
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,
示例25: render
点赞 5
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import format_html [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('', flatatt(final_attrs))
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:10,
注:本文中的django.utils.html.format_html方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。