当前位置: 首页>>代码示例>>Python>>正文


Python defaultfilters.escape方法代码示例

本文整理汇总了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 
开发者ID:wooey,项目名称:Wooey,代码行数:19,代码来源:wooey_celery.py

示例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) 
开发者ID:Chris7,项目名称:django-djangui,代码行数:28,代码来源:djangui_celery.py

示例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, '&lt;some html &amp; special characters &gt; here') 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_escape.py

示例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') 
开发者ID:nesdis,项目名称:djongo,代码行数:4,代码来源:test_escape.py

示例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&nbsp;%s' % (YES_IMG, text[len(positive):])
            found = True
            break

    if not found:
        for noinfo in NOINFO_KEYWORDS:
            if text.startswith(noinfo):
                text = '%s&nbsp;%s' % (NOINFO_IMG, text[len(noinfo):])
                found = True
                break

    if not found:
        for negative in NO_KEYWORDS:
            if text.startswith(negative):
                text = '%s&nbsp;%s' % (NO_IMG, text[len(negative):])
                break


    return text 
开发者ID:wise-team,项目名称:steemprojects.com,代码行数:47,代码来源:grid_tags.py


注:本文中的django.template.defaultfilters.escape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。