Skip to content

Commit

Permalink
Provide a default __page_attribute__.
Browse files Browse the repository at this point in the history
This way `browserDefault` does not die with an AttributeError but
`__call__` will do it.
  • Loading branch information
Michael Howitz committed Jun 17, 2019
1 parent b5c4fa2 commit 261a955
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/zope/browserpage/metaconfigure.py
Expand Up @@ -404,6 +404,8 @@ def _handle_for(_context, for_):
@implementer(IBrowserPublisher)
class simple(BrowserView):

__page_attribute__ = '__call__'

def publishTraverse(self, request, name):
if name in getattr(self, "_simple__whitelist", []):
self.__page_attribute__ = name
Expand Down
8 changes: 4 additions & 4 deletions src/zope/browserpage/tests/test_page.py
Expand Up @@ -560,11 +560,11 @@ def testNamedViewNoPagesForNonCallable(self):

view = component.getMultiAdapter((ob, self.request), name='test')
view = removeSecurityProxy(view)
browser_default = view.browserDefault(self.request)
self.assertEqual(browser_default[1], '')
with self.assertRaises(AttributeError) as ctx:
view.browserDefault(self.request)
self.assertEqual(
str(ctx.exception),
"'test' object has no attribute '__page_attribute__'")
browser_default[0]()
self.assertEqual(str(ctx.exception), "__call__")

def testNamedViewPageViewsNoDefault(self):
self.assertEqual(
Expand Down

0 comments on commit 261a955

Please sign in to comment.