def objects(self): """The objects for which we want breadcrumbs.""" # Start the chain with the deepest object that has a breadcrumb. try: objects = [( obj for obj in reversed(self.request.traversed_objects) if IBreadcrumb(obj, None)).next()] except StopIteration: return [] # Now iterate. If an object has a breadcrumb, it can override # its parent. Otherwise we just follow the normal URL hierarchy # until we reach the end. while True: next_obj = None breadcrumb = IBreadcrumb(objects[0], None) if breadcrumb is not None: next_obj = breadcrumb.inside if next_obj is None: urldata = ICanonicalUrlData(objects[0], None) if urldata is not None: next_obj = urldata.inside if next_obj is None: break objects.insert(0, next_obj) return objects
def items(self): """Return a list of `IBreadcrumb` objects visible in the hierarchy. The list starts with the breadcrumb closest to the hierarchy root. """ breadcrumbs = [] for obj in self.objects: breadcrumb = IBreadcrumb(obj, None) if breadcrumb is not None: breadcrumbs.append(breadcrumb) facet = queryUtility(IFacet, name=get_facet(self._naked_context_view)) if breadcrumbs and facet is not None: # We have breadcrumbs and we're on a custom facet, so we'll # sneak an extra breadcrumb for the facet we're on. # Iterate over the context of our breadcrumbs in reverse order and # find the first one that implements IMultiFactedBreadcrumb. # It'll be facet-agnostic, so insert a facet-specific one # after it. for idx, breadcrumb in reversed(list(enumerate(breadcrumbs))): if IMultiFacetedBreadcrumb.providedBy(breadcrumb): facet_crumb = Breadcrumb( breadcrumb.context, rootsite=facet.rootsite, text=facet.text) alsoProvides(facet_crumb, IFacetBreadcrumb) breadcrumbs.insert(idx + 1, facet_crumb) # Ensure that all remaining breadcrumbs are # themselves faceted. for remaining_crumb in breadcrumbs[idx + 1:]: remaining_crumb.rootsite_override = facet.rootsite break if len(breadcrumbs) > 0: breadcrumbs.extend(self.makeBreadcrumbsForRequestedPage()) return breadcrumbs
def items(self): """Return a list of `IBreadcrumb` objects visible in the hierarchy. The list starts with the breadcrumb closest to the hierarchy root. """ breadcrumbs = [] for obj in self.objects: breadcrumb = IBreadcrumb(obj, None) if breadcrumb is not None: breadcrumbs.append(breadcrumb) host = URI(self.request.getURL()).host mainhost = allvhosts.configs['mainsite'].hostname if (len(breadcrumbs) != 0 and host != mainhost and self.vhost_breadcrumb): # We have breadcrumbs and we're not on the mainsite, so we'll # sneak an extra breadcrumb for the vhost we're on. vhost = host.split('.')[0] # Iterate over the context of our breadcrumbs in reverse order and # for the first one we find an adapter named after the vhost we're # on, generate an extra breadcrumb and insert it in our list. for idx, breadcrumb in reversed(list(enumerate(breadcrumbs))): extra_breadcrumb = queryAdapter( breadcrumb.context, IBreadcrumb, name=vhost) if extra_breadcrumb is not None: breadcrumbs.insert(idx + 1, extra_breadcrumb) break if len(breadcrumbs) > 0: page_crumb = self.makeBreadcrumbForRequestedPage() if page_crumb: breadcrumbs.append(page_crumb) return breadcrumbs
def text(self): return IBreadcrumb(self.context.distroseries).text
def test_breadcrumb(self): # Person products give the product as their breadcrumb url. pp = self._makePersonProduct() breadcrumb = IBreadcrumb(pp, None) self.assertEqual(canonical_url(pp.product), breadcrumb.url)
def test_breadcrumb(self): # Person DSPs give the DSP as their breadcrumb url. pdsp = self._makePersonDistributionSourcePackage() breadcrumb = IBreadcrumb(pdsp, None) self.assertEqual(canonical_url(pdsp.distro_source_package), breadcrumb.url)