当前位置: 首页>>代码示例>>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;未经允许,请勿转载。