Skip to content
Myr

improved djangosupport

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by David Cramer · committed by David Cramer · parent 1d51f63 · Browse files · 2 files+21 added−18 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+21 added−18 removed

  • other:+21 added−18 removed

2 files+21 added−18 removed

modified:jinja/contrib/_djangosupport.py+20 added-18 removed
1# -*- coding: utf-8 -*-2# -*- coding: utf-8 -*-3"""4 jinja.contrib._djangosupport5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~6
3 unmodified lines
10 The public interface is `jinja.contrib.djangosupport` and11 `django.contrib.jinja`. See the docstring of `jinja.contrib.djangosupport`12 for more details.1313 :copyright: 2007 by Armin Ronacher, Bryan McLemore.14 :copyright: 2007-2008 by Armin Ronacher, Bryan McLemore, David Cramer.15 :license: BSD, see LICENSE for more details.16"""17import sys18import warnings19import new20from django.conf import settings21from django.template.context import get_standard_processors22from django.http import HttpResponse
10 unmodified lines
33env = None343536#: default filters35DEFAULT_FILTERS = [37DEFAULT_FILTERS = (38 'django.template.defaultfilters.date',39 'django.template.defaultfilters.timesince',40 'django.template.defaultfilters.linebreaks',41 'django.contrib.humanize.templatetags.humanize.intcomma'40]42)434244def configure(convert_filters=DEFAULT_FILTERS, loader=None, **options):45 """46 Initialize the system.47 """48 global env4949 if env is not None:50 raise RuntimeError('jinja already configured')50 if env:51 warnings.warn("Jinja already initialized.")52 return5354 # setup environment55 if loader is None:54 loaders = [FileSystemLoader(l) for l in settings.TEMPLATE_DIRS]56 loaders = tuple(FileSystemLoader(l) for l in settings.TEMPLATE_DIRS)57 if not loaders:58 loader = None59 elif len(loaders) == 1:60 loader = loaders[0]
24 unmodified lines
85 module = contrib.jinja = sys.modules['django.contrib.jinja'] = \86 new.module('django.contrib.jinja')87 module.env = env88 module.__doc__ = djangosupport.__doc__87 module.register = Library()89 module.register = Library90 public_names = module.__all__ = ['register', 'env']91 get_name = globals().get92 for name in exported:93 setattr(module, name, get_name(name))
28 unmodified lines
122 def filter_factory(*args):123 def wrapped(env, ctx, value):124 return f(value, *args)125 return wrapped124 try:125 filter_factory.__name__ = f.__name__126 filter_factory.__doc__ = f.__doc__126 filter_factory.__name__ = f.__name__127 filter_factory.__doc__ = getattr(f, '__doc__', None)127 except:128 pass128 return filter_factory129130131class Library(object):
4 unmodified lines
136 This is available in `django.contrib.jinja` as `register`.137138 For more details see the docstring of the `django.contrib.jinja` module.139 """141 __slots__ = ()142143 def object(obj, name=None):140 @staticmethod141 def object(func, name=None):142 """Register a new global."""143 if name is None:146 name = getattr(obj, '__name__')147 env.globals[name] = obj144 name = getattr(func, '__name__')145 env.globals[name] = func146 return func147148 @staticmethod149 def filter(func, name=None):150 """Register a new filter function."""151 if name is None:152 name = func.__name__153 env.filters[name] = func154 return func155156 @staticmethod157 def test(func, name):158 """Register a new test function."""159 if name is None:160 name = func.__name__161 env.tests[name] = func162 return func163164 @staticmethod165 def context_inclusion(func, template, name=None):166 """167 Similar to the inclusion tag from django this one expects func to be a168 function with a similar argument list to func(context, *args, **kwargs)
16 unmodified lines
185 except:186 pass187 env.globals[name] = wrapper188189 @staticmethod190 def clean_inclusion(func, template, name=None, run_processors=False):191 """192 Similar to above however it won't pass the context into func().193 Also the returned context will have the context processors run upon it.
17 unmodified lines
modified:THANKS+1 added
7 unmodified lines
8- Axel Böhm9- Alexey Melchakov10- Stefan Ebner11- Bryan McLemore12- David Cramer