本文整理汇总了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)
示例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)
示例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)
示例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)