[Zope-Checkins] SVN: Zope/branches/philikon-aq/lib/python/Products/Five/browser/metaconfigure.py Simplify by using more machinery from Zope 3 (which we can thanks to IBrowserPUblisher

Philipp von Weitershausen philikon at philikon.de
Mon Jul 30 17:10:42 EDT 2007


Log message for revision 78482:
  Simplify by using more machinery from Zope 3 (which we can thanks to IBrowserPUblisher
  support since Zope 2.10)
  

Changed:
  U   Zope/branches/philikon-aq/lib/python/Products/Five/browser/metaconfigure.py

-=-
Modified: Zope/branches/philikon-aq/lib/python/Products/Five/browser/metaconfigure.py
===================================================================
--- Zope/branches/philikon-aq/lib/python/Products/Five/browser/metaconfigure.py	2007-07-30 20:59:22 UTC (rev 78481)
+++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/metaconfigure.py	2007-07-30 21:10:41 UTC (rev 78482)
@@ -29,10 +29,10 @@
 from zope.publisher.interfaces.browser import IBrowserRequest, \
      IDefaultBrowserLayer
 
-from zope.app.publisher.browser.viewmeta import pages as zope_app_pages
-from zope.app.publisher.browser.viewmeta import view as zope_app_view
-from zope.app.publisher.browser.viewmeta import providesCallable, \
-     _handle_menu, _handle_for
+import zope.app.publisher.browser.viewmeta
+import zope.app.pagetemplate.simpleviewclass
+from zope.app.publisher.browser.viewmeta import (providesCallable,
+                                                 _handle_menu, _handle_for)
 
 from Products.Five.browser import BrowserView
 from Products.Five.browser.resource import FileResourceFactory
@@ -159,7 +159,7 @@
         args = (new_class,)
         )
 
-class pages(zope_app_pages):
+class pages(zope.app.publisher.browser.viewmeta.pages):
 
     def page(self, _context, name, attribute='__call__', template=None,
              menu=None, title=None):
@@ -172,7 +172,7 @@
 
 # view (named view with pages)
 
-class view(zope_app_view):
+class view(zope.app.publisher.browser.viewmeta.view):
 
     def __call__(self):
         (_context, name, for_, permission, layer, class_,
@@ -389,33 +389,23 @@
             args = (new_class,)
             )
 
-#
-# mixin classes / class factories
-#
+class ViewMixinForAttributes(BrowserView,
+                             zope.app.publisher.browser.viewmeta.simple):
 
-class ViewMixinForAttributes(BrowserView):
+    # For some reason, the 'simple' baseclass doesn't implement this
+    # mandatory method (see https://bugs.launchpad.net/zope3/+bug/129296)
+    def browserDefault(self, request):
+        return getattr(self, self.__page_attribute__), ()
 
-    # we have an attribute that we can simply tell ZPublisher to go to
-    def __browser_default__(self, request):
-        return self, (self.__page_attribute__,)
+    # __call__ should have the same signature as the original method
+    @property
+    def __call__(self):
+        return getattr(self, self.__page_attribute__)
 
-    # this is technically not needed because ZPublisher finds our
-    # attribute through __browser_default__; but we also want to be
-    # able to call pages from python modules, PythonScripts or ZPT
-    __call__ = property(lambda self: getattr(self, self.__page_attribute__))
+class ViewMixinForTemplates(BrowserView,
+                            zope.app.pagetemplate.simpleviewclass.simple):
+    pass
 
-class ViewMixinForTemplates(BrowserView):
-
-    # short cut to get to macros more easily
-    def __getitem__(self, name):
-        if name == 'macros':
-            return self.index.macros
-        return self.index.macros[name]
-
-    # make the template publishable
-    def __call__(self, *args, **kw):
-        return self.index(self, *args, **kw)
-
 def makeClassForTemplate(filename, globals=None, used_for=None,
                          bases=(), cdict=None, name=u''):
     # XXX needs to deal with security from the bases?



More information about the Zope-Checkins mailing list