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
Provenance
- Commit
42e9b75- Tree
08f46fd- Author
David Cramer <dcramer@gmail.com>- Committer
David Cramer <dcramer@gmail.com>- Parent
1d51f63
2 files changed+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 lines10 The public interface is `jinja.contrib.djangosupport` and11 `django.contrib.jinja`. See the docstring of `jinja.contrib.djangosupport`12 for more details.13 13- :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 """17 import sys18+import warnings19 import new20 from django.conf import settings21 from django.template.context import get_standard_processors22 from django.http import HttpResponse10 unmodified lines33 env = None34 35 36 #: default filters35-DEFAULT_FILTERS = [37+DEFAULT_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+)43 42-44 def configure(convert_filters=DEFAULT_FILTERS, loader=None, **options):45 """46 Initialize the system.47 """48 global env49 49- if env is not None:50- raise RuntimeError('jinja already configured')50+ if env:51+ warnings.warn("Jinja already initialized.")52+ return53 54 # 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 lines85 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 lines122 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_factory129 130 131 class Library(object):4 unmodified lines136 This is available in `django.contrib.jinja` as `register`.137 138 For more details see the docstring of the `django.contrib.jinja` module.139 """141- __slots__ = ()142-143- 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 func147 148+ @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 func155 156+ @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 func163 164+ @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 lines185 except:186 pass187 env.globals[name] = wrapper188 189+ @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 linesmodified:THANKS+1 added
7 unmodified lines8 - Axel Böhm9 - Alexey Melchakov10 - Stefan Ebner11 - Bryan McLemore12+- David Cramer