RE: [Zope] Product initilization, acquisition and instance refere nces
Dylan, Most definitely ! Here's the relevant code: from Globals import Persistent, DTMLFile, InitializeClass from AccessControl.Role import RoleManager from AccessControl import ClassSecurityInfo from Acquisition import Implicit from OFS import SimpleItem from ogclib.WFS import GETQuery <--- My python module def addWFSGETQuery(self, id, connection, typename, title='', propertyname='', featureversion='', maxfeatures='', featureid='', filter='', bbox='', REQUEST=None): """ Add a WFS GET Query object """ self._setObject( id, WFSGETQuery(id, connection, typename, title, propertyname, featureversion, maxfeatures, featureid, filter, bbox ) ) if REQUEST is not None: REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main') class WFSGETQuery( GETQuery, SimpleItem.Item, Persistent, Implicit, RoleManager ): <- The Zope wrapper for my module def __init__( self, id, connection, typename, title='', propertyname='', featureversion='', maxfeatures='', featureid='', filter='', bbox='' ): self.id = id self.edit( connection, typename, title, propertyname, featureversion, maxfeatures, featureid, filter, bbox ) security.declareProtected( 'Change Database Methods' , 'edit' ) def edit(self, connection, typename, title='', propertyname='', featureversion='', maxfeatures='', featureid='', filter='', bbox='' ): self.connection = connection self.typename = typename self.title = title self.propertyname = propertyname self.featureversion = featureversion self.maxfeatures = maxfeatures self.featureid = featureid self.filter = filter self.bbox = bbox self._cleanupparams() <--- provided by GETQuery # Get feature type information and validate self._getfeaturetypeinfo() <--- Provided by GETQuery The problem is that outside of zope "connection" is an instance of another class ("Connection") ... _getfeatureinfo() which is called by edit which is called by __init__ needs that instance in order to do some work. But I can't get that instance because getattr doesn't find it !! (Even though it is there, in the same folder, available to be acquired) The strange thing is that before I wrote the classes into python modules, I had the whole thing as pure Zope products, and everythng was working fine. then I split it into two in order to have the functionality as regular Python modules, and when I come back into Zope, the same thing no longer works ? Thanks, J.F. -----Original Message----- From: Dylan Reinhardt [mailto:zope@dylanreinhardt.com] Sent: Wednesday, September 10, 2003 4:27 PM To: Jean-Francois.Doyon@ccrs.nrcan.gc.ca Cc: Zope Users Subject: Re: [Zope] Product initilization, acquisition and instance references On Wed, 2003-09-10 at 12:49, Jean-Francois.Doyon@CCRS.NRCan.gc.ca wrote:
The problem is the second one, which uses the first one. First of all, it looks like while the class is being instanciated, there isn't any acquisition yet ?
Did you use the Acquisition.Implicit mixin when you defined the class? HTH, Dylan
On Thu, 2003-09-11 at 06:31, Jean-Francois.Doyon@CCRS.NRCan.gc.ca wrote:
The problem is that outside of zope "connection" is an instance of another class ("Connection") ... _getfeatureinfo() which is called by edit which is called by __init__ needs that instance in order to do some work. But I can't get that instance because getattr doesn't find it !! (Even though it is there, in the same folder, available to be acquired)
Without seeing the code that breaks or being able to play with it... The first thing I'd try is using restrictedTraverse() instead of getattr(). That may just do the trick. Another easy thing I would try is using this same process to extract an attribute of a built-in object. If that fails in the same way, we at least know we're troubleshooting the correct object. Then it gets more difficult. Some things are tough to do during product initialization. I'm a bit fuzzy on the details so I won't try to explain. It's also possible that you're using getattr in a way that Acquisition context has been lost... maybe this is a case where the magic __of__() method needs to be used to provide a Acquisition wrapper. If those ideas don't work, are you getting any tracebacks? When an item isn't found, what happens? HTH, Dylan
participants (2)
-
Dylan Reinhardt -
Jean-Francois.Doyon@CCRS.NRCan.gc.ca