예제 #1
0
    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
예제 #2
0
 def test_detail(self):
     # The detail properted is the _detail attribute or the text attribute.
     cookbook = Cookbook()
     breadcrumb = Breadcrumb(cookbook)
     breadcrumb._detail = 'hello'
     breadcrumb.text = 'goodbye'
     self.assertEqual('hello', breadcrumb.detail)
     breadcrumb._detail = None
     self.assertEqual('goodbye', breadcrumb.detail)
 def test_detail(self):
     # The detail properted is the _detail attribute or the text attribute.
     cookbook = Cookbook()
     breadcrumb = Breadcrumb(cookbook)
     breadcrumb._detail = 'hello'
     breadcrumb.text = 'goodbye'
     self.assertEqual('hello', breadcrumb.detail)
     breadcrumb._detail = None
     self.assertEqual('goodbye', breadcrumb.detail)