[Checkins] SVN: z3c.pt/trunk/ The ViewPageTemplateFile class now uses the module path of the calling class to get an absolute path. This brings back the functionality removed in r89580, but localized to the template class only.
Malthe Borch
mborch at gmail.com
Sun Aug 24 07:46:17 EDT 2008
Log message for revision 90169:
The ViewPageTemplateFile class now uses the module path of the calling class to get an absolute path. This brings back the functionality removed in r89580, but localized to the template class only.
Changed:
U z3c.pt/trunk/CHANGES.txt
U z3c.pt/trunk/src/z3c/pt/pagetemplate.py
-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt 2008-08-24 11:44:37 UTC (rev 90168)
+++ z3c.pt/trunk/CHANGES.txt 2008-08-24 11:46:17 UTC (rev 90169)
@@ -4,6 +4,10 @@
Version 1.0dev
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- The ``ViewPageTemplateFile`` class now uses the module path of the
+ calling class to get an absolute path to a relative filename passed
+ to the constructor. [malthe]
+
- Added limited support for the XInclude ``include`` directive. The
implemented subset corresponds to the Genshi implementation, except
Match-templates, which are not made available to the calling
Modified: z3c.pt/trunk/src/z3c/pt/pagetemplate.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/pagetemplate.py 2008-08-24 11:44:37 UTC (rev 90168)
+++ z3c.pt/trunk/src/z3c/pt/pagetemplate.py 2008-08-24 11:46:17 UTC (rev 90169)
@@ -5,6 +5,8 @@
import template
import config
import zpt
+import sys
+import os
def prepare_language_support(kwargs):
target_language = kwargs.get('target_language')
@@ -46,6 +48,12 @@
prepare_language_support(kwargs)
class ViewPageTemplate(property):
+ """Template class suitable for use with a Zope browser view; the
+ variables ``view``, ``context`` and ``request`` variables are
+ brought in to the local scope of the template automatically, while
+ keyword arguments are passed in through the ``options``
+ dictionary."""
+
def __init__(self, body, **kwargs):
self.template = PageTemplate(body, **kwargs)
property.__init__(self, self.render)
@@ -60,6 +68,26 @@
return template
class ViewPageTemplateFile(ViewPageTemplate):
+ """If ``filename`` is a relative path, the module path of the
+ class where the instance is used to get an absolute path."""
+
def __init__(self, filename, **kwargs):
+ if not os.path.isabs(filename):
+ for depth in (1, 2):
+ frame = sys._getframe(depth)
+ package_name = frame.f_globals['__name__']
+
+ if package_name != self.__module__:
+ break
+
+ module = sys.modules[package_name]
+ try:
+ path = module.__path__[0]
+ except AttributeError:
+ path = module.__file__
+ path = path[:path.rfind(os.sep)]
+
+ filename = path + os.sep + filename
+
self.template = PageTemplateFile(filename)
property.__init__(self, self.render)
More information about the Checkins
mailing list