當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。