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
# 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
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'])
else:
target_lang = 'en'
- return make_locale_lower_upper_style(target_lang)
+ return locale_to_lower_upper(target_lang)