[z3-checkins] r9730 - in z3/Five/trunk: . tests

jw at codespeak.net jw at codespeak.net
Thu Mar 10 23:50:44 MET 2005


Author: jw
Date: Thu Mar 10 23:50:43 2005
New Revision: 9730

Modified:
   z3/Five/trunk/browser.py
   z3/Five/trunk/tests/test_five.py
Log:
Make Five's default IAbsoluteUrl.breadcrumbs() implementation
stop at the virtual host root, like Zope-3 does.


Modified: z3/Five/trunk/browser.py
==============================================================================
--- z3/Five/trunk/browser.py	(original)
+++ z3/Five/trunk/browser.py	Thu Mar 10 23:50:43 2005
@@ -72,24 +72,30 @@
     __call__ = __str__
 
     def breadcrumbs(self):
-        context = self.context
+        context = self.context.aq_inner
+        container = context.aq_parent
         request = self.request
 
-        container = aq_parent(aq_inner(context))
-        if container is None or not ITraversable.providedBy(container):
-            return ({'name': context.getId(),
-                     'url': context.absolute_url()
-                     },)
+        name = context.getId()
+        
+        if container is None or self._isVirtualHostRoot() \
+            or not ITraversable.providedBy(container):
+            return (
+                {'name': 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))
-                  },)
+        base += (
+            {'name': name, 'url': ("%s/%s" % (base[-1]['url'], name))},)
 
         return base
 
+    def _isVirtualHostRoot(self):
+        virtualrootpath = self.request.get('VirtualRootPhysicalPath', None)
+        if virtualrootpath is None:
+            return False
+        context = self.context.aq_inner
+        return context.restrictedTraverse(virtualrootpath) == context
 
 class SiteAbsoluteURL(AbsoluteURL):
     """An adapter for Zope3-style absolute_url using Zope2 methods

Modified: z3/Five/trunk/tests/test_five.py
==============================================================================
--- z3/Five/trunk/tests/test_five.py	(original)
+++ z3/Five/trunk/tests/test_five.py	Thu Mar 10 23:50:43 2005
@@ -211,6 +211,20 @@
             {'url': 'http://nohost/test_folder_1_/testoid', 'name': 'testoid'})
         self.assertEquals(expected, view.breadcrumbs())
 
+    def test_virtualhost_breadcrumbs(self):
+        # Get REQUEST in shape
+        request = self.request = self.app.REQUEST
+        request['PARENTS'] = [self.folder.test_folder_1_]
+        request.setServerURL(
+            protocol='http', hostname='foo.bar.com', port='80')
+        request.setVirtualRoot('')
+            
+        view = self.folder.unrestrictedTraverse('testoid/@@absolute_url')
+        expected = (
+            {'url': 'http://foo.bar.com', 'name': 'test_folder_1_'},
+            {'url': 'http://foo.bar.com/testoid', 'name': 'testoid'})
+        self.assertEquals(expected, view.breadcrumbs())
+        
     def test_containement_root_breadcrumbs(self):
         # Should stop breadcrumbs from crumbing
         directlyProvides(self.folder, IContainmentRoot)


More information about the z3-checkins mailing list