template: hack to defer template to a script (#7209)

This commit is contained in:
Frédéric Péters 2015-05-12 11:37:51 +02:00
parent f03781948a
commit 859788bb02
1 changed files with 16 additions and 2 deletions

View File

@ -27,6 +27,15 @@ from quixote.html import htmltext, htmlescape, TemplateIO
import errors
import ezt
def get_template_from_script(filename):
local_result = {}
execfile(filename, {
'publisher': get_publisher(),
'request': get_request()}, local_result)
return local_result.get('template_content')
def get_theme_directory(theme_id):
system_location = os.path.join(get_publisher().data_dir, 'themes', theme_id)
local_location = os.path.join(get_publisher().app_dir, 'themes', theme_id)
@ -354,7 +363,7 @@ def decorate(body, response):
template_ezt = get_cfg('branding', {}).get('template')
if response.page_template_key or not template_ezt:
# the theme can provide a default template
possible_filenames = []
possible_filenames = ['template.py']
if response.page_template_key:
possible_filenames.append('template.%s.%s.ezt' % (
get_publisher().APP_NAME, response.page_template_key))
@ -373,7 +382,12 @@ def decorate(body, response):
for dname in possible_dirnames:
filename = os.path.join(dname, fname)
if os.path.exists(filename):
template_ezt = file(filename).read()
if fname == 'template.py':
template_ezt = get_template_from_script(filename)
if template_ezt is None:
continue
else:
template_ezt = file(filename).read()
break
else:
continue