I am in the process of upgrading from Plone 5.1 to Plone 5.2. I am past the initial obstacles pertaining to the upgrade, but I am still working on bringing my custom add-ons up to speed. One of my customizations relies on getting a viewlet by name, which has a Plone Docs example.
https://docs.plone.org/develop/plone/views/viewlets.html
def setupViewletByName(self, name):
""" Constructs a viewlet instance by its name.
Viewlet update() and render() method are not called.
@return: Viewlet instance of None if viewlet with name does not exist
"""
context = aq_inner(self.context)
request = self.request
# Perform viewlet regisration look-up
# from adapters registry
reg = self.getViewletByName(name)
if reg == None:
return None
# factory method is responsible for creating the viewlet instance
factory = reg.factory
# Create viewlet and put it to the acquisition chain
# Viewlet need initialization parameters: context, request, view
try:
viewlet = factory(context, request, self, None).__of__(context)
except TypeError:
# Bad constructor call parameters
raise RuntimeError(
"Unable to initialize viewlet {}. Factory method {} call failed."
.format(name, str(factory)))
return viewlet
The problem is with the line: viewlet = factory(context, request, self, None).__of__(context)
.
It cannot acquisition wrap. So it gives: AttributeError: 'MyCustomViewlet' object has no attribute '__of__'
.
Is there a new equivalent for wrapping the acquisition for a viewlet, or is this a bigger problem with the upgrade from 5.1 to 5.2?
Any help is appreciated. Thank you!