← Back to team overview

launchpad-dev team mailing list archive

Breadcrumb changes

 

Hi Francis,

I've had a couple calls with Martin about our breadcrumbs, and one of
the things we want is to have an extra item for the first traversed
object on the vhost we're on, in case we're not on the mainsite. e.g.

  bugs.lp.net/bzr

would have

  Bazaar (lp.net/bzr) > Bugs (bugs.lp.net/bzr/+open-bugs)

as breadcrumbs. Note that the link of the new breadcrumb will not point
to the default (+index) page, so we must be able to customize that for
any obj/vhost.

Given that, it seemed reasonable to me to change our Hierarchy view to
sneak an extra item manually and use named adapters (having the vhost as
the name) so that we can get an IBreadcrumbBuilder for this extra item.

How does this sound to you? The small patch attached shows what it'd
look like.

Cheers,

-- 
Guilherme Salgado <salgado@xxxxxxxxxxxxx>
=== modified file 'lib/canonical/launchpad/browser/launchpad.py'
--- lib/canonical/launchpad/browser/launchpad.py	2009-08-10 14:32:44 +0000
+++ lib/canonical/launchpad/browser/launchpad.py	2009-08-11 18:28:11 +0000
@@ -235,10 +235,21 @@
                 continue
             pathurls.append(working_url)
 
+        uri = URI(self.request.getURL())
+        objects = self.request.traversed_objects[:]
+        if uri.host != config.vhosts.mainsite.hostname:
+            # We're not on the mainsite, so we want an extra crumb for the
+            # first traversed object on the vhost we're on.
+            vhost = uri.host.split('.')[0]
+            objects.insert(1, (objects[0], vhost))
+            # The URL for these breadcrumbs vary depending on the vhost, so it
+            # must be defined in the relevant IBreadcrumbBuilder.
+            pathurls.insert(1, None)
+
         # We assume a 1:1 relationship between the traversed_objects list and
         # the URL path segments.  Note that there may be more segments than
         # there are objects.
-        object_urls = zip(self.request.traversed_objects, pathurls)
+        object_urls = zip(objects, pathurls)
         return self._breadcrumbs(object_urls)
 
     def _breadcrumbs(self, object_urls):
@@ -255,17 +266,23 @@
         return breadcrumbs
 
     def breadcrumb_for(self, obj, url):
-        """Return the breadcrumb for the an object, using the supplied URL.
+        """Return the breadcrumb for an object, using the supplied URL.
 
         :return: An `IBreadcrumb` object, or None if a breadcrumb adaptation
             for the object doesn't exist.
         """
+        if isinstance(obj, tuple):
+            obj, vhost = obj
+        else:
+            vhost = None
         # If the object has an IBreadcrumbBuilder adaptation then the
         # object is intended to be shown in the hierarchy.
-        builder = queryAdapter(obj, IBreadcrumbBuilder)
+        builder = queryAdapter(obj, IBreadcrumbBuilder, name=vhost)
         if builder is not None:
-            # The breadcrumb builder hasn't been given a URL yet.
-            builder.url = url
+            # The breadcrumb builder hasn't been given a URL yet, so we set
+            # one if we have.
+            if url is not None:
+                builder.url = url
             return builder.make_breadcrumb()
         return None
 

Attachment: signature.asc
Description: This is a digitally signed message part


Follow ups