From 2c2691b7918d3b03b354feba4d40b6aba13e939a Mon Sep 17 00:00:00 2001 From: Marcel Jackwerth Date: Fri, 2 Mar 2012 17:28:51 +0100 Subject: [PATCH] Importing the filters with __import__ lookup. --- hyde/ext/templates/jinja.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hyde/ext/templates/jinja.py b/hyde/ext/templates/jinja.py index 0f0d01e..30b187f 100644 --- a/hyde/ext/templates/jinja.py +++ b/hyde/ext/templates/jinja.py @@ -655,6 +655,7 @@ class Jinja2Template(Template): settings.update(defaults) settings['extensions'] = list() settings['extensions'].extend(default_extensions) + settings['filters'] = {} conf = {} @@ -671,6 +672,15 @@ class Jinja2Template(Template): settings['extensions'].extend(extensions) else: settings['extensions'].append(extensions) + + filters = conf.get('filters', {}) + if isinstance(filters, dict): + for name, value in filters.items(): + parts = value.split('.') + module_name = '.'.join(parts[:-1]) + function_name = parts[-1] + module = __import__(module_name, fromlist=[function_name]) + settings['filters'][name] = getattr(module, function_name) self.env = Environment( loader=self.loader, @@ -694,7 +704,7 @@ class Jinja2Template(Template): self.env.filters['xmldatetime'] = xmldatetime self.env.filters['islice'] = islice self.env.filters['top'] = top - self.env.filters.update(conf.get('filters', dict())) + self.env.filters.update(settings['filters']) config = {} if hasattr(site, 'config'):