def test_defaultname(self): self.assertEquals( getDefaultViewName(Exception(), self.request), 'index.html') error = NotFound(object(), self.request) self.assertEquals( getDefaultViewName(error, self.request), 'index.html') self.assertEquals( getDefaultViewName( Unauthorized(), self.request), 'index.html')
def test_defaultname(self): self.assertEqual( getDefaultViewName(Exception(), self.request), 'index.html') self.assertEqual( getDefaultViewName( TraversalException(), self.request), 'index.html') self.assertEqual( getDefaultViewName( Unauthorized(), self.request), 'index.html') error = MethodNotAllowed(object(), self.request) self.assertEqual( getDefaultViewName(error, self.request), 'index.html')
def __init__(self, context, request): redirected_context = context.default_bugtask viewname = getDefaultViewName(redirected_context, request) cache_view = getMultiAdapter( (redirected_context, request), name=viewname) super(BugWithoutContextView, self).__init__( canonical_url(redirected_context), request, cache_view=cache_view)
def makeBreadcrumbsForRequestedPage(self): """Return a sequence of `IBreadcrumb`s 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 view is the default one for the object or the current facet, no breadcrumbs are returned -- we'll have injected a facet Breadcrumb earlier in the hierarchy which links here. """ url = self.request.getURL() obj = self.request.traversed_objects[-2] default_view_name = getDefaultViewName(obj, self.request) view = self._naked_context_view default_views = [default_view_name] facet = queryUtility(IFacet, name=get_facet(view)) if facet is not None: default_views.append(facet.default_view) crumbs = [] # Views may provide an additional breadcrumb to precede them. # This is useful to have an add view link back to its # collection despite its parent being the context of the collection. if hasattr(view, 'inside_breadcrumb'): crumbs.append(view.inside_breadcrumb) if hasattr(view, '__name__') and view.__name__ not in default_views: 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) crumbs.append(Breadcrumb(None, url=url, text=title)) return crumbs
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
def browserDefault(self, request): ob = self.context if list(providedBy(ob)): view_name = getDefaultViewName(ob, request) return ob, (("@@%s" % view_name),) return ob, ()
def browserDefault(self, request): """See zope.container.traversal.ContainerTraverser. -> context, (view_uri,) """ default_name = self.default_name if default_name is None: default_name = getDefaultViewName(self, request) return self, (default_name,)
def browserDefault(self, request): """See zope.container.traversal.ContainerTraverser. -> context, (view_uri,) """ default_name = self.default_name if default_name is None: default_name = getDefaultViewName(self, request) return self, (default_name, )
def browserDefault(self, request): ob = self.context providedIfaces = [iface for iface in providedBy(ob)] if providedIfaces: view_name = getDefaultViewName(ob, request) return ob, (("@@%s" % view_name),) return ob, ()
def browserDefault(self, request): # if we have a RESTful request, we will handle # GET, POST and HEAD differently (PUT and DELETE are handled already # but not on the BrowserRequest layer but the HTTPRequest layer) if IRESTLayer.providedBy(request): rest_view = component.getMultiAdapter( (self.context, self.request), name=request.method) return rest_view, () view_name = getDefaultViewName(self.context, request) view_uri = "@@%s" % view_name return self.context, (view_uri,)
def testDefaultView(self): self.assertIsNone( component.queryMultiAdapter((ob, request), IDefaultViewName)) xmlconfig( templated(''' <browser:defaultView name="test" for="zope.publisher.tests.test_zcml.IOb" /> ''')) self.assertEqual(getDefaultViewName(ob, request), 'test')
def testDefaultView(self): self.assertTrue( component.queryMultiAdapter((ob, request), IDefaultViewName) is None) xmlconfig(StringIO(template % ( ''' <browser:defaultView name="test" for="zope.publisher.tests.test_zcml.IOb" /> ''' ))) self.assertEqual(getDefaultViewName(ob, request), 'test')
def browserDefault(self, request): ob = self.context view_name = getDefaultViewName(ob, request) view = self.publishTraverse(request, view_name) if hasattr(view, 'browserDefault'): view, path = view.browserDefault(request) if len(path) == 1: view = view.publishTraverse(request, path[0]) path = () else: path = () return view, path
def __call__(self): """Return the JSON cache.""" if IBrowserPublisher.providedBy(self.context): view = self.context else: defaultviewname = getDefaultViewName(self.context, self.request) view = getMultiAdapter((self.context, self.request), name=defaultviewname) if view is None: return naked_view = removeSecurityProxy(view) naked_view.initialize() cache = naked_view.getCacheJSON() self.request.response.setHeader('content-type', 'application/json') return cache
def __call__(self): """Return the JSON cache.""" if IBrowserPublisher.providedBy(self.context): view = self.context else: defaultviewname = getDefaultViewName( self.context, self.request) view = getMultiAdapter( (self.context, self.request), name=defaultviewname) if view is None: return naked_view = removeSecurityProxy(view) naked_view.initialize() cache = naked_view.getCacheJSON() self.request.response.setHeader('content-type', 'application/json') return cache
def browserDefault(self, request): view_name = getDefaultViewName(self.context, request) return self.context, (view_name, )
def browserDefault(self, request): # content = self.getContent(request) content = self.context view_name = getDefaultViewName(content, request) view_uri = "@@%s" % view_name return content, (view_uri,)
def browserDefault(self, request): """See zope.publisher.browser.interfaces.IBrowserPublisher""" view_name = getDefaultViewName(self.context, request) view_uri = "@@%s" % view_name return self.context, (view_uri,)
def authorized(self, result): obj = result.object() defaultview = getDefaultViewName(obj, self.request) view = queryMultiAdapter((ProxyFactory(obj), self.request), name=defaultview) return canAccess(view, "__call__")
def browserDefault(self, request): """See zope.publisher.browser.interfaces.IBrowserPublisher""" view_name = getDefaultViewName(self.context, request) view_uri = "@@%s" % view_name return self.context, (view_uri, )
def browserDefault(self, request): ob = self.context view_name = getDefaultViewName(ob, request) return ob, (view_name,)