diff options
Diffstat (limited to 'mediagoblin/tools/template.py')
-rw-r--r-- | mediagoblin/tools/template.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/mediagoblin/tools/template.py b/mediagoblin/tools/template.py index a773ca99..0986761b 100644 --- a/mediagoblin/tools/template.py +++ b/mediagoblin/tools/template.py @@ -17,18 +17,19 @@ from math import ceil import jinja2 from babel.localedata import exists -from babel.support import LazyProxy from mediagoblin import mg_globals from mediagoblin import messages from mediagoblin.tools import common from mediagoblin.tools.translate import setup_gettext from mediagoblin.middleware.csrf import render_csrf_form_token + SETUP_JINJA_ENVS = {} + def get_jinja_env(template_loader, locale): """ - Set up the Jinja environment, + Set up the Jinja environment, (In the future we may have another system for providing theming; for now this is good enough.) @@ -51,15 +52,19 @@ def get_jinja_env(template_loader, locale): # All templates will know how to ... # ... fetch all waiting messages and remove them from the queue # ... construct a grid of thumbnails or other media + # ... have access to the global and app config template_env.globals['fetch_messages'] = messages.fetch_messages template_env.globals['gridify_list'] = gridify_list template_env.globals['gridify_cursor'] = gridify_cursor + template_env.globals['app_config'] = mg_globals.app_config + template_env.globals['global_config'] = mg_globals.global_config if exists(locale): SETUP_JINJA_ENVS[locale] = template_env return template_env + # We'll store context information here when doing unit tests TEMPLATE_TEST_CONTEXT = {} @@ -76,8 +81,8 @@ def render_template(request, template_path, context): context['request'] = request context['csrf_token'] = render_csrf_form_token(request) rendered = template.render(context) - - if common.TESTS_ENABLED: + + if common.TESTS_ENABLED: TEMPLATE_TEST_CONTEXT[template_path] = context return rendered @@ -87,6 +92,7 @@ def clear_test_template_context(): global TEMPLATE_TEST_CONTEXT TEMPLATE_TEST_CONTEXT = {} + def gridify_list(this_list, num_cols=5): """ Generates a list of lists where each sub-list's length depends on |