[z3-checkins] r5665 - z3/Five/branch/dc-experiments

dreamcatcher at codespeak.net dreamcatcher at codespeak.net
Sat Jul 24 22:37:53 MEST 2004


Author: dreamcatcher
Date: Sat Jul 24 22:37:53 2004
New Revision: 5665

Modified:
   z3/Five/branch/dc-experiments/browser.py
Log:

- AbsoluteURL view (also useful for breadcrumbs).
- StandardMacros view, useful for getting to templates macros in a
  sane way



Modified: z3/Five/branch/dc-experiments/browser.py
==============================================================================
--- z3/Five/branch/dc-experiments/browser.py	(original)
+++ z3/Five/branch/dc-experiments/browser.py	Sat Jul 24 22:37:53 2004
@@ -10,9 +10,18 @@
 
 $Id$
 """
+
 import Acquisition
+from  Acquisition import aq_inner, aq_parent, aq_base
 from AccessControl import ClassSecurityInfo
 from Globals import InitializeClass
+from interfaces import ITraversable
+from zope.interface import implements
+from zope.interface.common.mapping import IItemMapping
+from zope.component import getView
+from zope.component import getViewProviding
+from zope.app.traversing.browser.interfaces import IAbsoluteURL
+
 
 class BrowserView(Acquisition.Explicit):
     security = ClassSecurityInfo()
@@ -25,3 +34,63 @@
     # as this makes Zope 2 traverse into that first!
 
 InitializeClass(BrowserView)
+
+class AbsoluteURL(BrowserView):
+    """An adapter for Zope3-style absolute_url
+    view using Zope2 methods
+    """
+
+    implements(IAbsoluteURL)
+
+    def __str__(self):
+        context = self.context
+        return context.absolute_url()
+
+    __call__ = __str__
+
+    def breadcrumbs(self):
+        context = self.context
+        request = self.request
+
+        container = aq_parent(aq_inner(context))
+        if container is None or not ITraversable.providedBy(container):
+            return ({'name': '',
+                     'url': context.absolute_url()
+                     },)
+
+        view = getViewProviding(container, IAbsoluteURL, request)
+        base = tuple(view.breadcrumbs())
+        name = context.getId()
+        base += ({'name': name,
+                  'url': ("%s/%s" % (base[-1]['url'], name))
+                  },)
+
+        return base
+
+
+class Macros:
+
+    implements(IItemMapping)
+
+    macro_pages = ()
+    aliases = {
+        'view': 'page',
+        'dialog': 'page',
+        'addingdialog': 'page'
+        }
+
+    def __getitem__(self, key):
+        key = self.aliases.get(key, key)
+        context = self.context
+        request = self.request
+        for name in self.macro_pages:
+            page = getView(context, name, request)
+            try:
+                v = page[key]
+            except KeyError:
+                pass
+            else:
+                return v
+        raise KeyError, key
+
+class StandardMacros(BrowserView, Macros): pass


More information about the z3-checkins mailing list