本文整理汇总了Python中django.utils.safestring.mark_safe方法的典型用法代码示例。如果您正苦于以下问题:Python safestring.mark_safe方法的具体用法?Python safestring.mark_safe怎么用?Python safestring.mark_safe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.safestring
的用法示例。
在下文中一共展示了safestring.mark_safe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: accessories
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def accessories(request, pk, device_id):
from django.utils import safestring
if request.POST.get('name'):
a = Accessory(name=request.POST['name'])
a.order_id = pk
a.device_id = device_id
a.save()
choice_list = []
choices = Accessory.objects.distinct('name')
for c in choices:
choice_list.append(c.name)
action = reverse('orders-accessories', args=[pk, device_id])
selected = Accessory.objects.filter(order_id=pk, device_id=device_id)
choices_json = safestring.mark_safe(json.dumps(choice_list))
return render(request, 'devices/accessories_edit.html', locals())
示例2: render
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [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)
示例3: render_option
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [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),
)
示例4: answers
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def answers(self, obj):
field_template = "<li><input type=\"checkbox\" data-change-url=\"%s\" data-field-entry=\"%d\" data-document=\"%d\" data-entry-value=\"%s\" %s><span class=\"%s\">%s</span>: <strong>%s</strong> - <em>%s</em></li>"
rv = '<ul>'
form_fields = obj.form.fields.order_by('id').all()
rv += ''.join([field_template % (reverse('admin:document_set_field_entry_change', args=(obj.document.pk, e.pk,)),
e.pk,
obj.document.pk,
e.value,
'checked' if e.verified else '',
'verify' if f.verify else '',
f.label,
e.value,
e.assigned_canonical_value())
for f, e in zip(form_fields,
obj.fields.order_by('field_id').all())])
rv += '</ul>'
return mark_safe(rv)
示例5: parent_
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def parent_(self, obj):
targetObject = None
if obj.parent:
targetObject = obj.parent
elif obj.speedrun:
targetObject = obj.speedrun
elif obj.event:
targetObject = obj.event
if targetObject:
return mark_safe(
'<a href={0}>{1}</a>'.format(
str(viewutil.admin_url(targetObject)), targetObject
)
)
else:
return '<None>'
示例6: index
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def index(request, **kwargs):
bundle = webpack_manifest.load(
os.path.abspath(
os.path.join(os.path.dirname(__file__), '../ui-tracker.manifest.json')
),
settings.STATIC_URL,
debug=settings.DEBUG,
timeout=60,
read_retry=None,
)
return render(
request,
'ui/index.html',
{
'event': Event.objects.latest(),
'events': Event.objects.all(),
'bundle': bundle.tracker,
'CONSTANTS': mark_safe(json.dumps(constants())),
'ROOT_PATH': reverse('tracker:ui:index'),
'app': 'TrackerApp',
'form_errors': {},
'props': '{}',
},
)
示例7: render_select_site_form
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def render_select_site_form(self, request, context, form_url=''):
"""
Render the site choice form.
"""
app_label = self.opts.app_label
context.update({
'has_change_permission': self.has_change_permission(request),
'form_url': mark_safe(form_url),
'opts': self.opts,
'add': True,
'save_on_top': self.save_on_top,
})
return render_to_response(self.select_site_form_template or [
'admin/%s/%s/select_site_form.html' % (app_label, self.opts.object_name.lower()),
'admin/%s/select_site_form.html' % app_label,
'admin/usersettings/select_site_form.html', # added default here
'admin/select_site_form.html'
], context)
示例8: question_preview_html
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def question_preview_html(self):
# override to present options (original order) along with question text
options = self.version.config.get('options', [])
permute = self.version.config.get('permute', 'keep')
q_html = self.question_html()
choices_html = [
'<p><span class="mc-letter">%s.</span> %s</p>' % (OPTION_LETTERS[i], escape(o[0]))
for i, o
in enumerate(options)
]
if permute == 'keep':
order_note = ''
else:
order_note = ' <span class="helptext">[Choices may have been presented in a different order during the quiz.]</span> '
return mark_safe(''.join((
'<div>',
q_html,
order_note,
''.join(choices_html),
'</div>'
)))
示例9: edit_attach
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def edit_attach(request, course_slug, case_slug):
"""
Front page of the file attachments interface
"""
course = get_object_or_404(CourseOffering, slug=course_slug)
case = get_object_or_404(DisciplineCaseBase, slug=case_slug, offering__slug=course_slug)
case = case.subclass()
attach_pub = CaseAttachment.objects.filter(case=case, public=True)
attach_pri = CaseAttachment.objects.filter(case=case, public=False)
if not case.can_edit('attach'):
# once case is closed, don't allow editing
return ForbiddenResponse(request)
groupmembersJSON = case.groupmembersJSON()
context = {'course': course, 'case': case, 'attach_pub': attach_pub, 'attach_pri': attach_pri,
'templatesJSON': '[]', 'groupmembersJSON': mark_safe(groupmembersJSON)}
return render(request, "discipline/show_attach.html", context)
示例10: field_display
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def field_display(field, safe=False):
out = []
if isinstance(field.field.widget, (forms.widgets.RadioSelect, forms.widgets.CheckboxSelectMultiple)):
out.append('<div class="field radio">%s</div>' % (str(field)))
else:
out.append('<div class="field">%s</div>' % (str(field)))
out.append(str(field.errors))
if field.help_text:
if isinstance(field.help_text, Promise):
out.append('<div class="helptext">%s</div>' % (escape(field.help_text)))
else:
if safe:
out.append('<div class="helptext">%s</div>' % (field.help_text))
else:
out.append('<div class="helptext">%s</div>' % (escape(field.help_text)))
return mark_safe('\n'.join(out))
示例11: label_display
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def label_display(field, prefix=''):
out = []
labelid = str(field.name)
if prefix:
labelid = prefix + '-' + labelid
if isinstance(field.field.widget, (RadioSelect, SupervisorWidget)):
labelid += '_0'
out.append('<label for="id_%s">' % (labelid,))
out.append(escape(field.label))
out.append(':')
if field.field.required or (hasattr(field.field, 'force_display_required') and field.field.force_display_required):
out.append(' ' + required_icon)
out.append('</label>')
return mark_safe(''.join(out))
示例12: score_stars
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def score_stars(score, maxscore):
"""
Turn the results score into 5 stars out of the max
"""
stars = 1.0 * STARS * score/maxscore
wholestars = int(stars)
frac = stars - wholestars
if frac >= 0.5:
halfstars = 1
else:
halfstars = 0
return mark_safe(
wholestars * '<i class="fa fa-star"></i>'
+ halfstars * '<i class="fa fa-star-half"></i>'
+ (STARS - wholestars - halfstars) * '<i class="fa fa-star-o"></i>'
)
示例13: display_form_as_row
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def display_form_as_row(form, arg=None):
"""
Convert the form to a HTML table row
set arg to be "deleted_flag" to include the deleted field
"""
output = ["<tr>"]
if arg == 'hidden':
output = ['<tr class="hidden">']
for field in form.visible_fields():
if field.name == "deleted" and (arg != "deleted_flag"):
output.append("<td></td>")
continue
c = Context({"field":field})
output.append( FIELD_AS_TD_TEMPLATE.render(c))
for field in form.hidden_fields():
c = Context({"field":field})
output.append( FIELD_AS_TD_TEMPLATE_HIDDEN.render(c))
output.append("</tr>")
return mark_safe('\n'.join(output))
# from http://stackoverflow.com/questions/35948/django-templates-and-variable-attributes
示例14: html_contents
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def html_contents(self, offering=None):
"""
Return the HTML version of this version's wikitext (with macros substituted if available)
offering argument only required if self.page isn't set: used when doing a speculative conversion of unsaved content.
Cached to save frequent conversion.
"""
key = self.html_cache_key()
html = cache.get(key)
if html:
return mark_safe(html)
else:
markup_content = self.substitute_macros(self.get_wikitext())
html = markup_to_html(markup_content, self.markup(), pageversion=self, html_already_safe=True)
cache.set(key, html, 24*3600) # expired if activities are changed (in signal below), or by saving a PageVersion in this offering
return mark_safe(html)
# signal for cache invalidation
示例15: to_html
# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import mark_safe [as 别名]
def to_html(self, fieldsubmission=None):
the_choices = [(k, v) for k, v in self.config.items() if k.startswith("choice_") and self.config[k]]
the_choices = sorted(the_choices, key=lambda choice: (int) (re.findall(r'\d+', choice[0])[0]))
initial = []
if fieldsubmission:
initial = fieldsubmission.data['info']
display_values = [dict(the_choices)[str(i)] for i in initial]
if display_values:
output = '<ul>'
for item in display_values:
output += '<li>%s</li>' % escape(str(item))
output += '</ul>'
else:
output = '<p class="empty">None selected</p>'
return mark_safe(output)