more legacy support and tests

parent ac95a5ec
......@@ -32,9 +32,9 @@ class BrowserView(zope.publisher.browser.BrowserView):
return self
# XXX Classes which are still based on Acquisition and access
# self.context in a method need to call aq_inner on it, or get a funky
# aq_chain. We do this here for BBB friendly purposes.
# Classes which are still based on Acquisition and access
# self.context in a method need to call aq_inner on it, or get a
# funky aq_chain. We do this here for BBB friendly purposes.
def __getParent(self):
return getattr(self, '_parent', Acquisition.aq_inner(self.context))
......@@ -45,9 +45,11 @@ class BrowserView(zope.publisher.browser.BrowserView):
aq_parent = __parent__ = property(__getParent, __setParent)
# We provide the aq_* properties here for BBB
aq_self = aq_inner = aq_base = property(lambda self: self)
aq_chain = property(Acquisition.aq_chain)
def aq_acquire(self, *args, **kw):
return Acquisition.aq_acquire(self, *args, **kw)
@property
def aq_chain(self):
return Acquisition.aq_chain(self)
def aq_inContextOf(self, *args, **kw):
return Acquisition.aq_inContextOf(self, *args, **kw)
......@@ -23,14 +23,29 @@ views still works (the printed output is the aq_chain of the view):
>>> print browser.contents
[<Products.Five.metaclass.LegacyAttributes object at ...>, <Folder at /test_folder_1_>, <Application at >, <ZPublisher.BaseRequest.RequestContainer object at ...>]
Let's also make sure that calling __of__ on a view has the desired
effect. First let's get a view:
Let's do some more manual tests with the view object. But first we
must get it:
>>> from zope.component import getMultiAdapter
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> view = getMultiAdapter((self.folder, request), name='attributes')
Let's try to acquire something from the root folder:
>>> button = view.aq_acquire('ZopeAttributionButton')
>>> print button()
<a href="http://www.zope.org/Credits" target="_top"><img src="http://nohost/p_/ZopeButton" width="115" height="50" border="0" alt="Powered by Zope" /></a>
Let's check that we're in the right context:
>>> view.aq_inContextOf(self.folder)
1
>>> view.aq_inContextOf(self.app)
1
>>> view.aq_inContextOf(object())
0
Let's try the __of__ protocol:
#>>> view = view.__of__(self.app)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment