RE: [Zope] Storing and Using Object references
Thanks for th pointer Shane, My original attempt with Andy's help was to use the REQUEST's resolve_url. However, the SiteAccess2 product breaks that method. I'll try your suggestions. Thanks Tom -Original Message- From: Shane Hathaway [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 10, 2001 3:11 PM To: Tom Jenkins Subject: Re: [Zope] Storing and Using Object references Tom Jenkins wrote: Hello all, i have a question and I hope someone can point me in the right direction to solve it. I need one zope object to hold a reference to another zope object so the first object can call methods of the second object. oh, these are python classes. Example: object 1 is : /container1/container1a/item1 object 2 is : /container2/container2a/item1 object1 needs to hold a reference to object2. I'm really stuck on how to store and access object2 from object1. any pointers? I think what you're looking for is getPhysicalPath() and unrestrictedTraverse(). Store object2.getPhysicalPath(), which returns a tuple, in object1. To find object2 again, call object1.unrestrictedTraverse(stored_physical_path). Note that this only works in Zope 2.2.x+. Shane - Tom Jenkins | xml devIS - Development InfoStructure | Its what you 703.525.6485 [EMAIL PROTECTED] | you need it http://www.devis.com | to be /xml ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
RE: [Zope] Storing and Using Object references
Shane, You are DA MAN. That getPhysicalPath() unrestrictedTraverse() methods work perfectly, even with SiteAccess installed. Thank you very much. Tom -Original Message- From: Shane Hathaway [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 10, 2001 3:11 PM To: Tom Jenkins Subject: Re: [Zope] Storing and Using Object references Tom Jenkins wrote: Hello all, i have a question and I hope someone can point me in the right direction to solve it. I need one zope object to hold a reference to another zope object so the first object can call methods of the second object. oh, these are python classes. Example: object 1 is : /container1/container1a/item1 object 2 is : /container2/container2a/item1 object1 needs to hold a reference to object2. I'm really stuck on how to store and access object2 from object1. any pointers? I think what you're looking for is getPhysicalPath() and unrestrictedTraverse(). Store object2.getPhysicalPath(), which returns a tuple, in object1. To find object2 again, call object1.unrestrictedTraverse(stored_physical_path). Note that this only works in Zope 2.2.x+. Shane Tom Jenkins |xml Its devIS - Development InfoStructure |all you 703.525.6485 [EMAIL PROTECTED] |need it http://www.devis.com |to be/xml ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re:[Zope] Storing and Using Object references
Tom Jenkins [EMAIL PROTECTED] wrote Hello all, i have a question and I hope someone can point me in the right direction to solve it. I need one zope object to hold a reference to another zope object so the first object can call methods of the second object. oh, these are python classes. Example: object 1 is : /container1/container1a/item1 object 2 is : /container2/container2a/item1 object1 needs to hold a reference to object2. I'm really stuck on how to store and access object2 from object1. any pointers? If you store the path to the other object as an attribute on its referer, then you can use the OFS.Traversal interface to fetch the referred object on demand. E.g.:: class Foo: bar_path = None def setBar( self, bar ): """ Save bar's path so we can find it later. """ if bar is None: self.bar_path is None else: self.bar_path = bar.getPhysicalPath() def getBar( self ): """ Use stored path to retrieve bar. """ if self.bar_path is None: return None return self.restrictedTraverse( self.bar_path ) #^_could be 'unrestrictedTraverse', in trusted code Tres -- === Tres Seaver[EMAIL PROTECTED] Digital Creations "Zope Dealers" http://www.zope.org ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] Storing and Using Object references
Hello all, i have a question and I hope someone can point me in the right direction to solve it. I need one zope object to hold a reference to another zope object so the first object can call methods of the second object. oh, these are python classes. Example: object 1 is : /container1/container1a/item1 object 2 is : /container2/container2a/item1 object1 needs to hold a reference to object2. I'm really stuck on how to store and access object2 from object1. any pointers? Tom Jenkins devis - Development InfoStructure http://www.devis.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Storing and Using Object references
If you call /container1/container1a/container2/container2a/item1, you can call methods on anything in the path... You could access it through dtml from 1-2 as dtml-with "container1.container1a.item1"dtml-call method/dtml-with You could get object2 in using getItem... -- Andy McKay. - Original Message - From: "Tom Jenkins" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, January 10, 2001 8:48 PM Subject: [Zope] Storing and Using Object references Hello all, i have a question and I hope someone can point me in the right direction to solve it. I need one zope object to hold a reference to another zope object so the first object can call methods of the second object. oh, these are python classes. Example: object 1 is : /container1/container1a/item1 object 2 is : /container2/container2a/item1 object1 needs to hold a reference to object2. I'm really stuck on how to store and access object2 from object1. any pointers? Tom Jenkins devis - Development InfoStructure http://www.devis.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev ) ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Storing and Using Object references
Hi Andy, Thanks for the feedback. Yes I see that I can call the methods using the url (which will give me the object) but I thought that was only in dtml. I need to access the object in my python code. that's the struggle I'm having. or did I miss something in your response? Tom "Andy McKay" wrote: Subject: Re: [Zope] Storing and Using Object references Date: Wed, 10 Jan 2001 08:56:25 -0800 From: "Andy McKay" [EMAIL PROTECTED] To: [EMAIL PROTECTED], [EMAIL PROTECTED] If you call /container1/container1a/container2/container2a/item1, you can call methods on anything in the path... You could access it through dtml from 1-2 as dtml-with "container1.container1a.item1"dtml-call method/dtml-with You could get object2 in using getItem... -- Andy McKay. - Original Message - From: "Tom Jenkins" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, January 10, 2001 8:48 PM Subject: [Zope] Storing and Using Object references Hello all, i have a question and I hope someone can point me in the right direction to solve it. I need one zope object to hold a reference to another zope object so the first object can call methods of the second object. oh, these are python classes. Example: object 1 is : /container1/container1a/item1 object 2 is : /container2/container2a/item1 object1 needs to hold a reference to object2. I'm really stuck on how to store and access object2 from object1. any pointers? Tom Jenkins devis - Development InfoStructure http://www.devis.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Storing and Using Object references
In python its even easier, and depends what you are doing. Basically you want to get a handle to another object so you can do something along the lines of obj = self.container1.containter1a.item1 result = obj.mymethod() there are many funky variations on that of course. There's also interfaces such as REQUEST.resolve_url, _getOb, getItem that you may want to look into. -- Andy McKay. - Original Message - From: "Tom Jenkins" [EMAIL PROTECTED] To: "Andy McKay" [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, January 10, 2001 10:54 PM Subject: Re: [Zope] Storing and Using Object references Hi Andy, Thanks for the feedback. Yes I see that I can call the methods using the url (which will give me the object) but I thought that was only in dtml. I need to access the object in my python code. that's the struggle I'm having. or did I miss something in your response? Tom "Andy McKay" wrote: Subject: Re: [Zope] Storing and Using Object references Date: Wed, 10 Jan 2001 08:56:25 -0800 From: "Andy McKay" [EMAIL PROTECTED] To: [EMAIL PROTECTED], [EMAIL PROTECTED] If you call /container1/container1a/container2/container2a/item1, you can call methods on anything in the path... You could access it through dtml from 1-2 as dtml-with "container1.container1a.item1"dtml-call method/dtml-with You could get object2 in using getItem... -- Andy McKay. - Original Message - From: "Tom Jenkins" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, January 10, 2001 8:48 PM Subject: [Zope] Storing and Using Object references Hello all, i have a question and I hope someone can point me in the right direction to solve it. I need one zope object to hold a reference to another zope object so the first object can call methods of the second object. oh, these are python classes. Example: object 1 is : /container1/container1a/item1 object 2 is : /container2/container2a/item1 object1 needs to hold a reference to object2. I'm really stuck on how to store and access object2 from object1. any pointers? Tom Jenkins devis - Development InfoStructure http://www.devis.com ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev ) ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Storing and Using Object references
Tom Jenkins wrote: Hello all, i have a question and I hope someone can point me in the right direction to solve it. I need one zope object to hold a reference to another zope object so the first object can call methods of the second object. oh, these are python classes. Example: object 1 is : /container1/container1a/item1 object 2 is : /container2/container2a/item1 object1 needs to hold a reference to object2. I'm really stuck on how to store and access object2 from object1. any pointers? I think what you're looking for is getPhysicalPath() and unrestrictedTraverse(). Store object2.getPhysicalPath(), which returns a tuple, in object1. To find object2 again, call object1.unrestrictedTraverse(stored_physical_path). Note that this only works in Zope 2.2.x+. Shane ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )