Why do I get an attribute error when one tool calls another tool?
I can see that the MemberDataTool is able to call the portal_membership tool using the getToolByName method. (and there are hundreds more examples where this is successful) But when I try to do it I get an attribute error, (before you ask, yes the first tool has been successfully created first prior to me trying to add this second tool.): Traceback (innermost last): Module ZPublisher.Publish, line 101, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module Products.CMFCore.utils, line 427, in manage_addTool Module Products.ParasynPIP.ParasynChartTool, line 87, in __init__ Module Products.ParasynPIP.ParasynPIPChartTool, line 80, in getParasynPIPTool Module Products.CMFCore.utils, line 75, in getToolByName AttributeError: parasynpip_tool My code in the second tool looks like: def __init__(self): ppt = getToolByName(self,"parasynpip_tool") Any help anyone could provide would be fantastic, thanks in advance. My Install is zope 2.7.3, python 2.3, plone 2.0, no other installed products, on windoze, ____________________________________________ Peter Millar
Hi Peter - getToolByName depends on acquisition to work, and the one place that it doesn't work is in a constructor ;) HTH, Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com
-----Original Message----- From: zope-bounces@zope.org [mailto:zope-bounces@zope.org]On Behalf Of Peter Millar Sent: Sunday, December 05, 2004 8:32 PM To: Zope Subject: [Zope] Why do I get an attribute error when one tool calls anothertool?
I can see that the MemberDataTool is able to call the portal_membership tool using the getToolByName method. (and there are hundreds more examples where this is successful)
But when I try to do it I get an attribute error, (before you ask, yes the first tool has been successfully created first prior to me trying to add this second tool.):
Traceback (innermost last): Module ZPublisher.Publish, line 101, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module Products.CMFCore.utils, line 427, in manage_addTool Module Products.ParasynPIP.ParasynChartTool, line 87, in __init__ Module Products.ParasynPIP.ParasynPIPChartTool, line 80, in getParasynPIPTool Module Products.CMFCore.utils, line 75, in getToolByName AttributeError: parasynpip_tool
My code in the second tool looks like:
def __init__(self): ppt = getToolByName(self,"parasynpip_tool")
Any help anyone could provide would be fantastic, thanks in advance.
My Install is zope 2.7.3, python 2.3, plone 2.0, no other installed products, on windoze, ____________________________________________ Peter Millar
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Sun, Dec 05, 2004 at 09:13:16PM -0500, Brian Lloyd wrote:
Hi Peter -
getToolByName depends on acquisition to work, and the one place that it doesn't work is in a constructor ;)
Next hint: generally, if you need an acquisition context for something you do when an object is contstructed, then you should do it in manage_afterAdd() and not __init__(). -- Paul Winkler http://www.slinkp.com
Hi Peter,
getToolByName depends on acquisition to work, and the one place that it doesn't work is in a constructor ;) Yes, that's true, but I think you can make it work if you pass the REQUEST (or I think the object itself) that calls the init method. ie:
def manage_addMyProduct(self, p1, p2, ..., REQUEST=None, submit=None): """Method that is called to create an instance on the zope db""" #Do something here #Then create the object: myObj=MyProduct(self,p1,p2) self._setObject(id,boringObj) #Do request redirection things here class MyProduct: def __init__(self, callerObj, p1, p2): """Inits your product""" ppt=getToolByName(callerObj,"parasynpip_tool") I don't know if it is the right sintax, but once I did something similar. If I'm not wrong, it is on the book of Dieter, or it is on a message that he posted. Regards, Josef
Yes, that's true, but I think you can make it work if you pass the REQUEST (or I think the object itself) that calls the init method. ie:
def manage_addMyProduct(self, p1, p2, ..., REQUEST=None, submit=None): """Method that is called to create an instance on the zope db""" #Do something here #Then create the object: myObj=MyProduct(self,p1,p2) self._setObject(id,boringObj)
#Do request redirection things here
class MyProduct: def __init__(self, callerObj, p1, p2): """Inits your product""" ppt=getToolByName(callerObj,"parasynpip_tool")
That looks like a nasty workaround for something that you really should be doing in manage_afterAdd. jens
participants (5)
-
Brian Lloyd -
Jens Vagelpohl -
Josef Meile -
Paul Winkler -
Peter Millar