[Product-Developers] plone.app.layout ViewletBase and portal_url
Wichert Akkerman
wichert at wiggy.net
Fri Mar 7 10:34:11 UTC 2008
I'm debugging some code that broke in a very unexpected way:
(Pdb) p getToolByName(self, 'portal_url')
'http://localhost:8080/Plone'
That should return a tool, not a string. This turned out to be caused by
plone.app.layout.viewlets.common.ViewletBase.update which sets
self.portal_url to the portal URL. This looks harmless, but due to
acquisition this will break patterns like this:
class MyViewlet(ViewletBase):
def update(self):
super(MyViewlet, self).update()
self.mt=getToolByName(self.context, "portal_membership")
self.somemethod()
def somemethod(self):
return self.mt.ToolMethod()
the problem here is that in somemethod() self.mt gets acquisition wrapped in
the viewlet, so when ToolMethod does getToolByName(self, "portal_url") it
finds the portal_url variable ViewletBase.update set on the viewlet instead
of the tool.
I would like to rename that variable in ViewletBase to prevent this problem
but I do not have a good overview of how many people are relying on that
specific variable to be set. If you are relying on this please let me know
ASAP. If I here no objection I intend to rename the variable for the
upcoming Plone 3.1 alpha release.
Wichert.
--
Wichert Akkerman <wichert at wiggy.net> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.
More information about the Product-Developers
mailing list