From 6bbf6723892a547816df3079342a8cecb2a89a44 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sun, 17 Jun 2012 23:16:15 -0500 Subject: [PATCH] allow dynamical import in template, thanks Fran --- VERSION | 2 +- gluon/template.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index fe80b236..dd6bb228 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.00.0 (2012-06-17 23:12:45) dev +Version 2.00.0 (2012-06-17 23:16:11) dev diff --git a/gluon/template.py b/gluon/template.py index 8cdc8706..63a33eca 100644 --- a/gluon/template.py +++ b/gluon/template.py @@ -20,8 +20,12 @@ import cgi import cStringIO import logging try: + # have web2py from restricted import RestrictedError -except: + from globals import current +except ImportError: + # do not have web2py + current = None def RestrictedError(a,b,c): logging.error(str(a)+':'+str(b)+':'+str(c)) return RuntimeError @@ -430,9 +434,14 @@ class TemplateParser(object): if not filename.strip(): self._raise_error('Invalid template filename') + # Allow Views to include other views dynamically + context = self.context + if current and not "response" in context: + context["response"] = current.response + # Get the filename; filename looks like ``"template.html"``. # We need to eval to remove the quotes and get the string type. - filename = eval(filename, self.context) + filename = eval(filename, context) # Get the path of the file on the system. filepath = self.path and os.path.join(self.path, filename) or filename