def test_url(self): # The detail properted is the _detail attribute or the text attribute. cookbook = Cookbook() breadcrumb = Breadcrumb(cookbook) breadcrumb._url = '/hello' self.assertEqual('/hello', breadcrumb.url) breadcrumb._url = None self.assertEqual('http://launchpad.dev/cookbook', breadcrumb.url)
def makeBreadcrumbForRequestedPage(self): """Return an `IBreadcrumb` for the requested page. The `IBreadcrumb` for the requested page is created using the current URL and the page's name (i.e. the last path segment of the URL). If the requested page (as specified in self.request) is the default one for our parent view's context, return None. """ url = self.request.getURL() obj = self.request.traversed_objects[-2] default_view_name = getDefaultViewName(obj, self.request) view = self._naked_context_view if view.__name__ != default_view_name: title = getattr(view, 'page_title', None) if title is None: title = getattr(view, 'label', None) if isinstance(title, Message): title = i18n.translate(title, context=self.request) breadcrumb = Breadcrumb(None) breadcrumb._url = url breadcrumb.text = title return breadcrumb else: return None