Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/utils.py

Issue 29328589: Issue 3122 - Add testpages.web.sitekey_frame URL handler (Closed)
Patch Set: Removed unrelated commit that was accidentally uploaded previously Created Oct. 8, 2015, 11:26 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sitescripts/testpages/web/sitekey_frame.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/utils.py
diff --git a/sitescripts/utils.py b/sitescripts/utils.py
index ca53d3d809402624cb357d4a90a0f8e4b7bfd404..982a277625df4fa69131d28584fdf2cac89286fa 100644
--- a/sitescripts/utils.py
+++ b/sitescripts/utils.py
@@ -134,37 +134,38 @@ def encode_email_address(email):
_template_cache = {}
-def get_template(template, autoescape=True):
+def get_template(template, autoescape=True, template_path=siteScriptsPath):
"""Parses and returns a Jinja2 template"""
- key = (template, autoescape)
+ key = (template_path, template, autoescape)
if not key in _template_cache:
if autoescape:
- env = get_template_environment()
+ env = get_template_environment(template_path)
else:
- env = get_unescaped_template_environment()
+ env = get_unescaped_template_environment(template_path)
_template_cache[key] = env.get_template(template)
return _template_cache[key]
@cached(float("inf"))
-def get_template_environment():
+def get_template_environment(template_path):
"""
Returns a Jinja2 template environment with autoescaping enabled.
"""
from sitescripts.templateFilters import filters
import jinja2
- env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath), autoescape=True)
+ env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path),
+ autoescape=True)
env.filters.update(filters)
return env
@cached(float("inf"))
-def get_unescaped_template_environment():
+def get_unescaped_template_environment(template_path):
"""
Returns a Jinja2 template environment without autoescaping. Don't use this to
generate HTML files!
"""
from sitescripts.templateFilters import filters
import jinja2
- env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath))
+ env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path))
env.filters.update(filters)
return env
« no previous file with comments | « sitescripts/testpages/web/sitekey_frame.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld