def containerViews(_context, for_, contents=None, add=None, index=None, layer=IDefaultBrowserLayer): """Set up container views for a given content type.""" if for_ is None: raise ValueError("A for interface must be specified.") if contents is not None: from zope.app.menus import zmi_views page(_context, name='contents.html', permission=contents, for_=for_, layer=layer, class_=Contents, attribute='contents', menu=zmi_views, title=_('Contents')) if index is not None: page(_context, name='index.html', permission=index, for_=for_, layer=layer, class_=Contents, attribute='index') if add is not None: from zope.app.menus import zmi_actions viewObj = view(_context, name='+', layer=layer, for_=for_, permission=add, class_=Adding) menuItemDirective( _context, zmi_actions, for_, '+', _('Add'), permission=add, layer=layer, filter= 'python:modules["zope.app.container.browser.metaconfigure"].menuFilter(context, request)' ) viewObj.page(_context, name='index.html', attribute='index') viewObj.page(_context, name='action.html', attribute='action') viewObj()
def test_template_with_attr_not_equal_name(self): import os v = view(self.context, None) v.page(self.context, 'page_name', attribute='foo', template=os.path.join(os.path.dirname(__file__), 'test.pt')) v() action = self.context.actions[2] register = action['args'] new_class = register[1] self.assertTrue(hasattr(new_class, 'foo')) self.assertTrue(hasattr(new_class, 'page_name'))
def test_class_with_publish_traverse_name(self): class C(object): attr = 'the attr' def publishTraverse(self, *args): raise AssertionError("Never called") v = view(self.context, None, class_=C) v.pages.append(['page_name', 'attr', None]) v() action = self.context.actions[2] register = action['args'] new_class = register[1] instance = new_class(None, None) self.assertEqual(C.attr, instance.publishTraverse(None, 'page_name'))
def test_class_without_publish_traverse_name(self): class C(object): attr = 'the attr' v = view(self.context, None, class_=C) v.pages.append(['page_name', 'attr', None]) v() action = self.context.actions[2] register = action['args'] new_class = register[1] instance = new_class(None, None) self.assertEqual(C.attr, instance.publishTraverse(None, 'page_name')) with self.assertRaises(LookupError): instance.publishTraverse(None, 'something else')
def test_class_with_publish_traverse_other_name(self): class C(object): attr = 'the attr' def publishTraverse(self, *args): return 'default value' v = view(self.context, None, class_=C) v.pages.append(['page_name', 'attr', None]) v() action = self.context.actions[2] register = action['args'] new_class = register[1] instance = new_class(None, None) self.assertEqual('default value', instance.publishTraverse(None, 'something else'))
def containerViews(_context, for_, contents=None, add=None, index=None, layer=IDefaultBrowserLayer): """Set up container views for a given content type.""" if for_ is None: raise ValueError("A for interface must be specified.") if contents is not None: from zope.app.menus import zmi_views page( _context, name="contents.html", permission=contents, for_=for_, layer=layer, class_=Contents, attribute="contents", menu=zmi_views, title=_("Contents"), ) if index is not None: page(_context, name="index.html", permission=index, for_=for_, layer=layer, class_=Contents, attribute="index") if add is not None: from zope.app.menus import zmi_actions viewObj = view(_context, name="+", layer=layer, for_=for_, permission=add, class_=Adding) menuItemDirective( _context, zmi_actions, for_, "+", _("Add"), permission=add, layer=layer, filter='python:modules["zope.app.container.browser.metaconfigure"].menuFilter(context, request)', ) viewObj.page(_context, name="index.html", attribute="index") viewObj.page(_context, name="action.html", attribute="action") viewObj()
def test_class_without_attribute(self): v = view(self.context, None, class_=type(self)) v.pages.append([None, 'does not exist', None]) self._call = v self._check_raises('Undefined attribute')
def _callFUT(self, *args, **kwargs): self.view = view(self.context, None) self.view.page(self.context, 'Name', **kwargs)