Browse Source

Importing the filters with __import__ lookup.

main
Marcel Jackwerth 13 years ago
committed by Lakshmi Vyasarajan
parent
commit
2c2691b791
1 changed files with 11 additions and 1 deletions
  1. +11
    -1
      hyde/ext/templates/jinja.py

+ 11
- 1
hyde/ext/templates/jinja.py View File

@@ -655,6 +655,7 @@ class Jinja2Template(Template):
settings.update(defaults) settings.update(defaults)
settings['extensions'] = list() settings['extensions'] = list()
settings['extensions'].extend(default_extensions) settings['extensions'].extend(default_extensions)
settings['filters'] = {}


conf = {} conf = {}


@@ -671,6 +672,15 @@ class Jinja2Template(Template):
settings['extensions'].extend(extensions) settings['extensions'].extend(extensions)
else: else:
settings['extensions'].append(extensions) 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( self.env = Environment(
loader=self.loader, loader=self.loader,
@@ -694,7 +704,7 @@ class Jinja2Template(Template):
self.env.filters['xmldatetime'] = xmldatetime self.env.filters['xmldatetime'] = xmldatetime
self.env.filters['islice'] = islice self.env.filters['islice'] = islice
self.env.filters['top'] = top self.env.filters['top'] = top
self.env.filters.update(conf.get('filters', dict()))
self.env.filters.update(settings['filters'])


config = {} config = {}
if hasattr(site, 'config'): if hasattr(site, 'config'):


Loading…
Cancel
Save