diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-05-14 14:24:27 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2013-05-14 14:24:27 -0500 |
commit | f7a5c7c78c6dcf3dcb3b81efbedc9a333df49fb7 (patch) | |
tree | 7e491dac697f975fbeb9e69c53bd454d7ac108d3 /mediagoblin/tools/template.py | |
parent | 725404236ef66884e53e0ef83264524768cefb9c (diff) | |
download | mediagoblin-f7a5c7c78c6dcf3dcb3b81efbedc9a333df49fb7.tar.lz mediagoblin-f7a5c7c78c6dcf3dcb3b81efbedc9a333df49fb7.tar.xz mediagoblin-f7a5c7c78c6dcf3dcb3b81efbedc9a333df49fb7.zip |
Fully working context hooks, both template/view and global level, with tests
Needs documentation though... that's coming next :)
This commit sponsored by Luca Tius. Thanks Luca!
Diffstat (limited to 'mediagoblin/tools/template.py')
-rw-r--r-- | mediagoblin/tools/template.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/mediagoblin/tools/template.py b/mediagoblin/tools/template.py index 950fb5da..aab571f0 100644 --- a/mediagoblin/tools/template.py +++ b/mediagoblin/tools/template.py @@ -27,8 +27,7 @@ from mediagoblin import messages from mediagoblin import _version from mediagoblin.tools import common from mediagoblin.tools.translate import set_thread_locale -from mediagoblin.tools.pluginapi import ( - get_hook_templates, hook_transform) +from mediagoblin.tools.pluginapi import get_hook_templates, hook_transform from mediagoblin.tools.timesince import timesince from mediagoblin.meddleware.csrf import render_csrf_form_token @@ -81,6 +80,9 @@ def get_jinja_env(template_loader, locale): # allow for hooking up plugin templates template_env.globals['get_hook_templates'] = get_hook_templates + template_env.globals = hook_transform( + 'template_global_context', template_env.globals) + if exists(locale): SETUP_JINJA_ENVS[locale] = template_env @@ -106,9 +108,10 @@ def render_template(request, template_path, context): context['csrf_token'] = render_csrf_form_token(request) # allow plugins to do things to the context - context = hook_transform( - (request.controller_name, template_path), - context) + if request.controller_name: + context = hook_transform( + (request.controller_name, template_path), + context) rendered = template.render(context) |