當前位置: 首頁>>代碼示例>>Python>>正文


Python Library.filter方法代碼示例

本文整理匯總了Python中coffin.template.Library.filter方法的典型用法代碼示例。如果您正苦於以下問題:Python Library.filter方法的具體用法?Python Library.filter怎麽用?Python Library.filter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在coffin.template.Library的用法示例。


在下文中一共展示了Library.filter方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Library

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import filter [as 別名]
"""Jinja2-ports of many of Django's default filters.

TODO: Most of the filters in here need to be updated for autoescaping.
"""

from coffin.template import Library
from jinja2.runtime import Undefined
from jinja2 import filters

register = Library()

def url(view_name, *args, **kwargs):
    from coffin.template.defaulttags import url
    return url._reverse(view_name, args, kwargs)

register.filter(url, jinja2_only=True)
register.object(url)

@register.filter(jinja2_only=True)
def timesince(value, *arg):
    if value is None or isinstance(value, Undefined):
        return u''
    from django.utils.timesince import timesince
    return timesince(value, *arg)

@register.filter(jinja2_only=True)
def timeuntil(value, *args):
    if value is None or isinstance(value, Undefined):
        return u''
    from django.utils.timesince import timeuntil
    return timeuntil(value, *args)
開發者ID:WoLpH,項目名稱:coffin,代碼行數:33,代碼來源:defaultfilters.py

示例2: foo

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import filter [as 別名]
"""Register a portable filter with a Coffin library object.
"""

def foo(value):
    return "{foo}"

from coffin.template import Library
register = Library()
register.filter('foo', foo)
開發者ID:Deepwalker,項目名稱:coffin,代碼行數:11,代碼來源:portable_filters.py

示例3: jinja_safe_output

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import filter [as 別名]

def jinja_safe_output(value):
    return Markup(value)

def django_safe_output(value):
    return mark_safe(value)

def unsafe_output(value):
    return unicode(value)


def django_raw_output(value):
    return value

def django_escape_output(value):
    # Make sure the value is converted to unicode first, because otherwise,
    # if it is already SafeData (for example, when coming from the template
    # code), then mark_for_escaping would do nothing. We want to guarantee
    # a EscapeData return value in this filter though.
    return mark_for_escaping(unicode(value))


from coffin.template import Library
register = Library()
register.filter('needing_autoescape', needing_autoescape)
register.filter('jinja_safe_output', jinja_safe_output)
register.filter('django_safe_output', django_safe_output)
register.filter('django_raw_output', django_raw_output)
register.filter('unsafe_output', unsafe_output)
register.filter('django_escape_output', django_escape_output)
開發者ID:Deepwalker,項目名稱:coffin,代碼行數:32,代碼來源:compat_filters.py

示例4: environment

# 需要導入模塊: from coffin.template import Library [as 別名]
# 或者: from coffin.template.Library import filter [as 別名]
from jinja2 import environmentfilter, contextfilter

@environmentfilter
def environment(environment, value):
    return ""

@contextfilter
def context(context, value):
    return ""

def multiarg(value, arg1, arg2):
    return ""

def jinja_forced(value):
    return ""

def django_jinja_forced(value):
    # a django filter that returns a django-safestring. It will *only*
    # be added to jinja, and coffin will hopefully ensure the string
    # stays safe.
    from django.utils.safestring import mark_safe
    return mark_safe(value)


from coffin.template import Library
register = Library()
register.filter('environment', environment)
register.filter('context', context)
register.filter('multiarg', multiarg)
register.filter('jinja_forced', jinja_forced, jinja2_only=True)
register.filter('django_jinja_forced', django_jinja_forced, jinja2_only=True)
開發者ID:Deepwalker,項目名稱:coffin,代碼行數:33,代碼來源:jinja2_filters.py


注:本文中的coffin.template.Library.filter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。