Permalink
Browse files

When autoloading jinja filters use the special __all__ module variabl…

…e to import the filters, if it is not defined then just import any defined callables.
  • Loading branch information...
1 parent fcb2f3d commit 7cc62f9130fc9651e7258490874bbc3ca886ba90 @clsdaniel clsdaniel committed Sep 29, 2012
Showing with 9 additions and 1 deletion.
  1. +9 −1 tg/configuration/app_config.py
@@ -497,7 +497,15 @@ def setup_jinja_renderer(self):
try:
filter_package = self.package.__name__ + ".lib.templatetools"
autoload_lib = __import__(filter_package, {}, {}, ['jinja_filters'])
- autoload_filters = autoload_lib.jinja_filters.__dict__
+ try:
+ autoload_filters = dict(
+ map(lambda x: (x,autoload_lib.jinja_filters.__dict__[x]), autoload_lib.jinja_filters.__all__)
+ )
+ except AttributeError:
+ autoload_filters = dict(
+ filter(lambda x: callable(x[1]),
+ autoload_lib.jinja_filters.__dict__.iteritems())
+ )
except (ImportError, AttributeError):
autoload_filters = {}

0 comments on commit 7cc62f9

Please sign in to comment.