def set_view(context, request, name = None): name = request.GET.get('name', name) if name is None: raise ValueError("Need to specify a request with the GET variable name or simply a name parameter.") if get_view(context, request, view_name = name) is None: raise HTTPForbidden(u"There's no view registered for this content type with that name. " u"Perhaps you forgot to register the view for this context?") context.default_view = name if name != 'view': title = get_content_views(request.registry)[context.type_name][name] else: title = _("Default view") fm = get_flash_messages(request) fm.add(_("View set to '${title}'", mapping = {'title': title})) #Remove settings. Should this be a subscriber instead? It's a bit destructive too, especially if clearing this isn't needed if hasattr(context, '__view_settings__'): delattr(context, '__view_settings__') return HTTPFound(location = request.resource_url(context))
def query_view(self, context, name = '', default = ''): result = get_view(context, self.request, view_name = name) return result and name or default
def test_include(self): self.config.registry.settings['arche.includes'] = 'arche_introspect' self.config.include('arche') root = Root() request = testing.DummyRequest() self.failUnless(get_view(root, request, '__introspection__'))