本文整理汇总了Python中django.utils.html.escape方法的典型用法代码示例。如果您正苦于以下问题:Python html.escape方法的具体用法?Python html.escape怎么用?Python html.escape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.html
的用法示例。
在下文中一共展示了html.escape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: question_preview_html
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [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>'
)))
示例2: init_request
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def init_request(self, object_id, *args, **kwargs):
"The 'delete' admin view for this model."
self.obj = self.get_object(unquote(object_id))
if not self.has_delete_permission(self.obj):
raise PermissionDenied
if self.obj is None:
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_text(self.opts.verbose_name), 'key': escape(object_id)})
using = router.db_for_write(self.model)
# Populate deleted_objects, a data structure of all related objects that
# will also be deleted.
(self.deleted_objects, model_count, self.perms_needed, self.protected) = get_deleted_objects(
[self.obj], self.opts, self.request.user, self.admin_site, using)
示例3: test_admin_lti_passport_fields_read_only
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def test_admin_lti_passport_fields_read_only(self):
"""Model fields "oauth_consumer_key" and "shared_secret" should be read only."""
lti_passport = PlaylistLTIPassportFactory()
user = UserFactory(is_staff=True, is_superuser=True)
self.client.login(username=user.username, password="password")
response = self.client.get(
reverse("admin:core_ltipassport_change", args=[lti_passport.id])
)
self.assertContains(
response,
"""<div class="readonly">{oauth_consumer_key}</div>""".format(
oauth_consumer_key=lti_passport.oauth_consumer_key
),
)
self.assertContains(
response,
"""<div class="readonly">{shared_secret}</div>""".format(
shared_secret=escape(lti_passport.shared_secret)
),
)
示例4: run
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def run(self, lines):
new_lines = []
def audiofy(match):
url = match.group(0)
url = html_escape(url)
html = u'<audio controls><source src="{url}"><a href="{url}">{url}</a></audio>'.format(url=url)
return self.markdown.htmlStash.store(html, safe=True)
for line in lines:
if line.strip():
line = re.sub(PATTERN_RE, audiofy, line, flags=re.UNICODE)
new_lines.append(line)
return new_lines
示例5: run
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def run(self, lines):
new_lines = []
def videofy(match):
url = match.group(0)
url = html_escape(url)
html = u'<video controls><source src="{url}"><a href="{url}">{url}</a></video>'.format(url=url)
return self.markdown.htmlStash.store(html, safe=True)
for line in lines:
if line.strip():
line = re.sub(PATTERN_RE, videofy, line, flags=re.UNICODE)
new_lines.append(line)
return new_lines
示例6: test_autoescape
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def test_autoescape(self):
content = "\nPraesent <nonummy mi> \"in\fodio\".\r\n\t"
template_string = string.Template("""
{% load compact from utils %}
{% autoescape $SWITCH %}
[{% filter compact %}$CONTENT{% endfilter %}]
[{% filter compact %}{{ my_var }}{% endfilter %}]/[{{ my_var|compact }}]/
{% endautoescape %}
""")
for switch in ('on', 'off'):
with self.subTest(autoescape=switch):
template = Template(template_string.substitute(SWITCH=switch, CONTENT=content))
page = template.render(Context({'my_var': content}))
self.assertEqual(
page.replace(" "*16, "").strip(),
"[Praesent <nonummy mi> \"in odio\".]\n"
+ (escape if switch == 'on' else lambda x: x)("[Praesent <nonummy mi> \"in odio\".]/") * 2
)
示例7: test_var_input
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def test_var_input(self, autoescape=True, test_data=None):
# Values of type 'str' are expected to be split into a list of strings,
# and HTML-encoded on output if autoescape is "on" (output as-is otherwise).
# Values of other types are expected to be wrapped in a list as-is.
template_string = string.Template("""
{% load split from utils %}
{% autoescape $SWITCH %}
{% for x in my_var|split$SEP %}#{{ x }}#{% endfor %}
{% endautoescape %}
""")
for content, expected_values in (test_data or self.test_data):
for sep in expected_values:
with self.subTest(value=content, separator=sep):
template = Template(template_string.substitute(
SWITCH='on' if autoescape else 'off',
SEP=':"{}"'.format(sep) if sep else ''))
page = template.render(Context({'my_var': content}))
self.assertEqual(
page.strip(),
"".join("#{}#".format(escape(part) if autoescape else part) for part in expected_values[sep])
)
示例8: check_repo_status
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def check_repo_status(self, repo):
self.check_in_html("repo_%s" % repo.pk, repo.name)
branches = repo.branches.exclude(status=models.JobStatus.NOT_STARTED)
for branch in branches.all():
self.check_class("branch_%s" % branch.pk, "boxed_job_status_%s" % branch.status_slug())
prs = repo.pull_requests.filter(closed=False)
for pr in prs.all():
self.check_class("pr_status_%s" % pr.pk, "boxed_job_status_%s" % pr.status_slug())
pr_elem_id = "pr_%s" % pr.pk
pr_elem = self.check_in_html(pr_elem_id, escape(pr.title))
self.check_in_html(pr_elem_id, str(pr.number))
self.check_in_html(pr_elem_id, pr.username)
self.assertEqual(pr_elem.get_attribute("data-sort"), str(pr.number))
pr_elems = self.selenium.find_elements_by_xpath("//ul[@id='pr_list_%s']/li" % repo.pk)
# make sure PRs are sorted properly
for i, elem in enumerate(pr_elems):
pr_num = int(elem.get_attribute("data-sort"))
if i == 0:
prev_num = int(pr_num)
else:
self.assertLess(prev_num, pr_num)
prev_num = int(pr_num)
示例9: format_match
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def format_match(self, obj):
return escape(obj.username)
示例10: format_item_display
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def format_item_display(self, obj):
result = '<a href="{0}">{1}</a>'.format(
reverse(
'admin:tracker_{0}_change'.format(obj._meta.model_name), args=[obj.pk]
),
escape(str(obj)),
)
return mark_safe(result)
示例11: student_submissions
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def student_submissions(member, activity):
url = reverse('offering:quiz:submission_history', kwargs={
'course_slug': activity.offering.slug,
'activity_slug': activity.slug,
'userid': member.person.userid_or_emplid()
})
context = {
'url': url,
'fname': escape(member.person.first_name),
'lname': escape(member.person.last_name),
}
return mark_safe(STUDENT_TEMPLATE.format(**context))
示例12: to_html
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def to_html(self, questionanswer):
ans = questionanswer.answer.get('data', '')
if ans:
return mark_safe('<p>' + escape(ans) + '</p>')
else:
return MISSING_ANSWER_HTML
示例13: escape_break
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def escape_break(text: str) -> SafeText:
"""
Helper to display student-entered text reasonably (and safely).
"""
return mark_safe(linebreaks(escape(text)))
示例14: format_field
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def format_field(case, field):
"""
Format long-form text as required by the discipline module, making substitutions as appropriate.
"""
text = eval("case."+field)
if text is None or text.strip() == "":
return mark_safe('<p class="empty">None</p>')
if field == 'contact_email_text':
# special case: contact email is plain text
return mark_safe("<pre>" + escape(wrap(case.substitite_values(str(text)), 78)) + "</pre>")
else:
return mark_safe('<div class="disc-details">' + textile_restricted(case.substitite_values(str(text)), lite=False) + '</div>')
示例15: download_response
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def download_response(self, **kwargs):
response = HttpResponse(content_type="text/html;charset=utf-8")
content = """<title>%s</title><a href="%s">%s</a>""" % (escape(self.component.title), escape(self.url), escape(self.url))
response.write(content.encode('utf-8'))
return response