From: Christopher Allan Webber Date: Wed, 3 Dec 2014 17:17:31 +0000 (-0600) Subject: Reforming get_jinja_env to make better use of the MediaGoblinApp X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=753cfc3bb9326a8be2928f1289e908c3aa520649;p=mediagoblin.git Reforming get_jinja_env to make better use of the MediaGoblinApp --- diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 00aa4fab..9eb2e8f2 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -227,7 +227,7 @@ class MediaGoblinApp(object): # This should be moved over for certain, but how to deal with # request.locale? request.template_env = template.get_jinja_env( - self.template_loader, request.locale) + self, self.template_loader, request.locale) mg_request.setup_user_in_request(request) diff --git a/mediagoblin/tools/template.py b/mediagoblin/tools/template.py index b01196fd..f2619808 100644 --- a/mediagoblin/tools/template.py +++ b/mediagoblin/tools/template.py @@ -29,7 +29,6 @@ from mediagoblin import _version from mediagoblin.tools import common from mediagoblin.tools.translate import is_rtl from mediagoblin.tools.translate import set_thread_locale -from mediagoblin.tools.translate import get_locale_from_request 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 @@ -37,7 +36,7 @@ from mediagoblin.meddleware.csrf import render_csrf_form_token SETUP_JINJA_ENVS = {} -def get_jinja_env(template_loader, locale): +def get_jinja_env(app, template_loader, locale): """ Set up the Jinja environment, @@ -54,7 +53,7 @@ def get_jinja_env(template_loader, locale): # The default config does not require a [jinja2] block. # You may create one if you wish to enable additional jinja2 extensions, # see example in config_spec.ini - jinja2_config = mg_globals.global_config.get('jinja2', {}) + jinja2_config = app.global_config.get('jinja2', {}) local_exts = jinja2_config.get('extensions', []) # jinja2.StrictUndefined will give exceptions on references @@ -79,10 +78,10 @@ def get_jinja_env(template_loader, locale): # ... have access to the global and app config # ... determine if the language is rtl or ltr template_env.globals['fetch_messages'] = messages.fetch_messages - template_env.globals['app_config'] = mg_globals.app_config - template_env.globals['global_config'] = mg_globals.global_config + template_env.globals['app_config'] = app.app_config + template_env.globals['global_config'] = app.global_config template_env.globals['version'] = _version.__version__ - template_env.globals['auth'] = mg_globals.app.auth + template_env.globals['auth'] = app.auth template_env.globals['is_rtl'] = is_rtl(locale) template_env.filters['urlencode'] = url_quote_plus