[Zope3-checkins] CVS: Zope3/src/zope/app/pagetemplate - simpleviewclass.py:1.4 viewpagetemplatefile.py:1.3

Godefroid Chapelle gotcha@swing.be
Tue, 25 Mar 2003 06:23:39 -0500


Update of /cvs-repository/Zope3/src/zope/app/pagetemplate
In directory cvs.zope.org:/tmp/cvs-serv20400/app/pagetemplate

Modified Files:
	simpleviewclass.py viewpagetemplatefile.py 
Log Message:
merging template_usage branch

connection to menu usage still to be done



=== Zope3/src/zope/app/pagetemplate/simpleviewclass.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/pagetemplate/simpleviewclass.py:1.3	Fri Jan 31 05:46:18 2003
+++ Zope3/src/zope/app/pagetemplate/simpleviewclass.py	Tue Mar 25 06:23:08 2003
@@ -40,17 +40,17 @@
     def __getitem__(self, name):
         return self.index.macros[name]
 
-    def __call__(self, *args, **kw):
-        return self.index(self.request, *args, **kw)
+    def __call__(self, template_usage=u'', *args, **kw):
+        return self.index(template_usage, *args, **kw)
 
-def SimpleViewClass(src, offering=None, used_for=None, bases=()):
+def SimpleViewClass(src, offering=None, used_for=None, bases=(), usage=u''):
     if offering is None:
         offering = sys._getframe(1).f_globals
 
     bases += (simple, )
 
     class_ = type("SimpleViewClass from %s" % src, bases,
-                  {'index': ViewPageTemplateFile(src, offering)})
+                  {'index': ViewPageTemplateFile(src, offering, usage)})
 
     if used_for is not None:
         class_.__used_for__ = used_for


=== Zope3/src/zope/app/pagetemplate/viewpagetemplatefile.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/pagetemplate/viewpagetemplatefile.py:1.2	Wed Dec 25 09:13:06 2002
+++ Zope3/src/zope/app/pagetemplate/viewpagetemplatefile.py	Tue Mar 25 06:23:08 2003
@@ -21,11 +21,17 @@
 from zope.pagetemplate.pagetemplatefile import PageTemplateFile
 from zope.component import getView
 from zope.app.pagetemplate.engine import AppPT
+import sys
 
 class ViewPageTemplateFile(AppPT, PageTemplateFile):
     """Page Templates used as methods of views defined as Python classes.
     """
 
+    def __init__(self, filename, _prefix=None, usage=u''):
+        _prefix = self.get_path_from_prefix(_prefix)
+        super(ViewPageTemplateFile, self).__init__(filename, _prefix)
+        self.usage = usage
+
     def pt_getContext(self, instance, request, **_kw):
         # instance is a View component
         namespace = super(ViewPageTemplateFile, self).pt_getContext(**_kw)
@@ -35,11 +41,15 @@
         namespace['views'] = ViewMapper(context, request)
         return namespace
 
-    def __call__(self, instance, *args, **keywords):
+    def __call__(self, instance, template_usage=u'', *args, **keywords):
+        # parameter template_usage needed such as the publisher machinery
+        # can find it and extract it from the request
+        if not template_usage:
+            template_usage = self.usage
+        keywords["template_usage"] = template_usage
         namespace = self.pt_getContext(
             request=instance.request,
-            instance=instance,
-            args=args, options=keywords)
+            instance=instance, args=args, options=keywords)
         return self.pt_render(namespace)
 
     def __get__(self, instance, type=None):
@@ -63,8 +73,8 @@
         object.__setattr__(self, 'im_func', pt)
         object.__setattr__(self, 'im_self', ob)
 
-    def __call__(self, REQUEST=None, **kw):
-        return self.im_func(self.im_self, REQUEST, **kw)
+    def __call__(self, template_usage=u'', **kw):
+        return self.im_func(self.im_self, template_usage, **kw)
 
     def __getattr__(self, name):
         return getattr(self.im_func, name)