I want to make an external method which does the following : iterates over all the parents, if a parent is of a certain type, the title must be added to a list. However I don't know how to iterate over an object (ZClass) it's parents in Python/Zope. Can anybody help? def GetParentNames(self): obj=self result=[] while obj.parent<>nil: <-- this is wrong obj=obj.parent <-- this is wrong if obj.meta_type=='KBItem': result.append(obj.Title) return result Thanks in advance, Tom.
Tom, How about something like (untested): def GetParentNames(self): p=self.REQUEST.PARENTS[:] result=[] for obj in p: if obj.meta_type =='KBItem': result.append(obj.Title) return result HTH Phil phil.harris@zope.co.uk ----- Original Message ----- From: "Tom Deprez" <tom.deprez@uz.kuleuven.ac.be> To: <zope@zope.org> Sent: Tuesday, March 28, 2000 1:28 PM Subject: [Zope] External Method
I want to make an external method which does the following :
iterates over all the parents, if a parent is of a certain type, the title must be added to a list. However I don't know how to iterate over an object (ZClass) it's parents in Python/Zope. Can anybody help?
def GetParentNames(self): obj=self result=[] while obj.parent<>nil: <-- this is wrong obj=obj.parent <-- this is wrong if obj.meta_type=='KBItem': result.append(obj.Title) return result
Thanks in advance,
Tom.
_______________________________________________ Zope maillist - Zope@zope.org 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 )
Hi, Yes, this gives me parents, but it doesn't work for my problem : The external method is used for storing the information into a ZCatalog. Now, when the Catalog is updated, I get the wrong parents, I get the parents of the catalog and not of the object itself. :-( Somebody another idea? Tom.
Tom,
How about something like (untested):
def GetParentNames(self): p=self.REQUEST.PARENTS[:] result=[] for obj in p: if obj.meta_type =='KBItem': result.append(obj.Title) return result
HTH
Phil phil.harris@zope.co.uk
----- Original Message ----- From: "Tom Deprez" <tom.deprez@uz.kuleuven.ac.be> To: <zope@zope.org> Sent: Tuesday, March 28, 2000 1:28 PM Subject: [Zope] External Method
I want to make an external method which does the following :
iterates over all the parents, if a parent is of a certain type, the title must be added to a list. However I don't know how to iterate over an object (ZClass) it's parents in Python/Zope. Can anybody help?
def GetParentNames(self): obj=self result=[] while obj.parent<>nil: <-- this is wrong obj=obj.parent <-- this is wrong if obj.meta_type=='KBItem': result.append(obj.Title) return result
Thanks in advance,
Tom.
_______________________________________________ Zope maillist - Zope@zope.org 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 - Zope@zope.org 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 )
At 02:28 PM 3/28/00 +0200, you wrote:
I want to make an external method which does the following :
iterates over all the parents, if a parent is of a certain type, the title must be added to a list. However I don't know how to iterate over an object (ZClass) it's parents in Python/Zope. Can anybody help?
def GetParentNames(self): obj=self result=[] while obj.parent<>nil: <-- this is wrong obj=obj.parent <-- this is wrong if obj.meta_type=='KBItem': result.append(obj.Title) return result You should use a recursive mathod.
Write one method recursiveMethod: def recursiveMethod(obj): result = [] if obj.parent != None: result = recursiveMethod(obj) if obj.meta_type=='KBItem': result.append(obj.Title) return result Then call this method like: def GetParentNames(self): recursiveMethod(self) This code is untested, but should work. Regards, Stephan -- Stephan Richter - (901) 573-3308 - srichter@cbu.edu CBU - Physics & Chemistry; Framework Web - Web Design & Development PGP Key: 735E C61E 5C64 F430 4F9C 798E DCA2 07E3 E42B 5391
participants (3)
-
Phil Harris -
Stephan Richter -
Tom Deprez