aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2011-05-12 15:17:07 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2011-05-12 15:17:07 -0500
commit0e0e3d9aadd481353c9a4a44b37dcb68c1efbaab (patch)
tree9c11b4d427f08c8d303ff3258e521f64cdd08ebc
parentf62ccaac15728cca6dfef40ebc3c63b367f38cbf (diff)
downloadmediagoblin-0e0e3d9aadd481353c9a4a44b37dcb68c1efbaab.tar.lz
mediagoblin-0e0e3d9aadd481353c9a4a44b37dcb68c1efbaab.tar.xz
mediagoblin-0e0e3d9aadd481353c9a4a44b37dcb68c1efbaab.zip
Separation between setting up the template env and the template loader
for a glorious future where we have gettext in template context
-rw-r--r--mediagoblin/app.py7
-rw-r--r--mediagoblin/util.py20
2 files changed, 19 insertions, 8 deletions
diff --git a/mediagoblin/app.py b/mediagoblin/app.py
index 2a2f21cc..d124558d 100644
--- a/mediagoblin/app.py
+++ b/mediagoblin/app.py
@@ -40,7 +40,7 @@ class MediaGoblinApp(object):
email_sender_address, email_debug_mode,
user_template_path=None):
# Get the template environment
- self.template_env = util.get_jinja_env(user_template_path)
+ self.template_loader = util.get_jinja_loader(user_template_path)
# Set up storage systems
self.public_store = public_store
@@ -103,7 +103,10 @@ class MediaGoblinApp(object):
# Attach self as request.app
# Also attach a few utilities from request.app for convenience?
request.app = self
- request.template_env = self.template_env
+ request.locale = util.get_locale_from_request(request)
+
+ request.template_env = util.get_jinja_env(
+ self.template_loader, request.locale)
request.db = self.db
request.staticdirect = self.staticdirector
diff --git a/mediagoblin/util.py b/mediagoblin/util.py
index f02b5f51..ac977bdb 100644
--- a/mediagoblin/util.py
+++ b/mediagoblin/util.py
@@ -33,23 +33,31 @@ def _activate_testing():
TESTS_ENABLED = True
-def get_jinja_env(user_template_path=None):
+def get_jinja_loader(user_template_path=None):
"""
- Set up the Jinja environment, possibly allowing for user
+ Set up the Jinja template loaders, possibly allowing for user
overridden templates.
(In the future we may have another system for providing theming;
for now this is good enough.)
"""
if user_template_path:
- loader = jinja2.ChoiceLoader(
+ return jinja2.ChoiceLoader(
[jinja2.FileSystemLoader(user_template_path),
jinja2.PackageLoader('mediagoblin', 'templates')])
else:
- loader = jinja2.PackageLoader('mediagoblin', 'templates')
+ return jinja2.PackageLoader('mediagoblin', 'templates')
+
+def get_jinja_env(template_loader, locale):
+ """
+ Set up the Jinja environment,
+
+ (In the future we may have another system for providing theming;
+ for now this is good enough.)
+ """
return jinja2.Environment(
- loader=loader, autoescape=True,
+ loader=template_loader, autoescape=True,
extensions=['jinja2.ext.i18n'])
@@ -237,4 +245,4 @@ def get_locale_from_request(request):
else:
target_lang = 'en'
- return make_locale_lower_upper_style(target_lang)
+ return locale_to_lower_upper(target_lang)