本文整理汇总了Python中django.template.defaultfilters.escape方法的典型用法代码示例。如果您正苦于以下问题:Python defaultfilters.escape方法的具体用法?Python defaultfilters.escape怎么用?Python defaultfilters.escape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.defaultfilters
的用法示例。
在下文中一共展示了defaultfilters.escape方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_job_list
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import escape [as 别名]
def generate_job_list(job_query):
if job_query is None:
return []
jobs = []
for job in job_query:
jobs.append({
'id': job.pk,
'name': escape(job.job_name),
'description': escape(six.u('Script: {}\n{}').format(job.script_version.script.script_name, job.job_description)),
'url': reverse('wooey:celery_results', kwargs={'job_id': job.pk}),
'submitted': job.created_date.strftime('%b %d %Y, %H:%M:%S'),
'status': STATE_MAPPER.get(job.status, job.status),
})
return jobs
示例2: celery_status
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import escape [as 别名]
def celery_status(request):
# TODO: This function can use some sprucing up, design a better data structure for returning jobs
spanbase = "<span class='glyphicon {}' data-toggle='tooltip' data-trigger='hover' title='{}'></span>"
STATE_MAPPER = {
DjanguiJob.COMPLETED: spanbase.format('glyphicon-ok', _('Success')),
DjanguiJob.RUNNING: spanbase.format('glyphicon-refresh spinning', _('Executing')),
states.PENDING: spanbase.format('glyphicon-time', _('In queue')),
states.REVOKED: spanbase.format('glyphicon-stop', _('Halted')),
DjanguiJob.SUBMITTED: spanbase.format('glyphicon-hourglass', _('Waiting to be queued'))
}
user = request.user
if user.is_superuser:
jobs = DjanguiJob.objects.all()
else:
jobs = DjanguiJob.objects.filter(Q(user=None) | Q(user=user) if request.user.is_authenticated() else Q(user=None))
jobs = jobs.exclude(status=DjanguiJob.DELETED)
# divide into user and anon jobs
def get_job_list(job_query):
return [{'job_name': escape(job.job_name), 'job_status': STATE_MAPPER.get(job.status, job.status),
'job_submitted': job.created_date.strftime('%b %d %Y, %H:%M:%S'),
'job_id': job.pk,
'job_description': escape(six.u('Script: {}\n{}').format(job.script.script_name, job.job_description)),
'job_url': reverse('djangui:celery_results_info', kwargs={'job_id': job.pk})} for job in job_query]
d = {'user': get_job_list([i for i in jobs if i.user == user]),
'anon': get_job_list([i for i in jobs if i.user == None or (user.is_superuser and i.user != user)])}
return JsonResponse(d, safe=False)
示例3: test_escape_lazy_string
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import escape [as 别名]
def test_escape_lazy_string(self):
add_html = lazy(lambda string: string + 'special characters > here', str)
escaped = escape(add_html('<some html & '))
self.assertIsInstance(escaped, Promise)
self.assertEqual(escaped, '<some html & special characters > here')
示例4: test_non_string_input
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import escape [as 别名]
def test_non_string_input(self):
self.assertEqual(escape(123), '123')
示例5: style_element
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import escape [as 别名]
def style_element(text):
low_text = text.strip().lower()
if low_text in YES_KEYWORDS:
return YES_IMG
if low_text in NO_KEYWORDS:
return NO_IMG
if low_text in NOINFO_KEYWORDS:
return NOINFO_IMG
if plus_two_re.search(low_text):
return YES_IMG * 2
if minus_two_re.search(low_text):
return NO_IMG * 2
if plus_three_re.search(low_text):
return YES_IMG * 3
if minus_three_re.search(low_text):
return NO_IMG * 3
text = escape(text)
found = False
for positive in YES_KEYWORDS:
if text.startswith(positive):
text = '%s %s' % (YES_IMG, text[len(positive):])
found = True
break
if not found:
for noinfo in NOINFO_KEYWORDS:
if text.startswith(noinfo):
text = '%s %s' % (NOINFO_IMG, text[len(noinfo):])
found = True
break
if not found:
for negative in NO_KEYWORDS:
if text.startswith(negative):
text = '%s %s' % (NO_IMG, text[len(negative):])
break
return text