本文整理匯總了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)