def test_add_filter(self):
        library = Library()

        def func(value):
            return 'filter({})'.format(value)

        library.filter(func)
    simply ignore any invalid arguments passed in.
    """

    tags = set(['csrf_token'])

    def parse(self, parser):
        lineno = parser.stream.next().lineno
        return nodes.Output([
            self.call_method('_render', [nodes.Name('csrf_token', 'load')]),
        ]).set_lineno(lineno)

    def _render(self, csrf_token):
        from django.template.defaulttags import CsrfTokenNode
        return Markup(CsrfTokenNode().render({'csrf_token': csrf_token}))


# nicer import names
load = LoadExtension
url = URLExtension
cache = CacheExtension
spaceless = SpacelessExtension
csrf_token = CsrfTokenExtension

library = Library()

library.extension(load)
library.extension(url)
library.extension(cache)
library.extension(spaceless)
library.extension(csrf_token)
示例#3
0
through an interop-layer.

However, Jinja 2 provides room to improve the syntax of some of the
filters. Those can be overridden here.

TODO: Most of the filters in here need to be updated for autoescaping.
"""
from django.utils.translation import ugettext, ungettext
from jinja2 import filters
from jinja2 import Markup
from jinja2.runtime import Undefined

from django_cofingo.library import Library
from django_cofingo.utils import template_localtime

library = Library()


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


@library.filter
def timeuntil(value, *args):
    if value is None or isinstance(value, Undefined):
        return u''
    from django.utils.timesince import timeuntil
示例#4
0
    simply ignore any invalid arguments passed in.
    """

    tags = set(['csrf_token'])

    def parse(self, parser):
        lineno = parser.stream.next().lineno
        return nodes.Output([
            self.call_method('_render', [nodes.Name('csrf_token', 'load')]),
        ]).set_lineno(lineno)

    def _render(self, csrf_token):
        from django.template.defaulttags import CsrfTokenNode
        return Markup(CsrfTokenNode().render({'csrf_token': csrf_token}))


# nicer import names
load = LoadExtension
url = URLExtension
cache = CacheExtension
spaceless = SpacelessExtension
csrf_token = CsrfTokenExtension

library = Library()

library.extension(load)
library.extension(url)
library.extension(cache)
library.extension(spaceless)
library.extension(csrf_token)