[Zope] External Method 3

Rik Hoekstra rik.hoekstra@inghist.nl
Fri, 31 Mar 2000 11:35:15 +0200


Tom Deprez wrote:
> 
> >> Well, the external method is defined in a ZClass and a catalog uses it to
> >> index the result. When I use the hasattr() I receive nothing (not even an
> >> empty list). If I use the split() method, then I receive a list with all
> >> the names.
> >
> >Yes, that's because the split does something else.
> >Don't know if you want to pursue this further, but if so, let's try and
> >track it down
> 
> Well, normally it should always give me an empty list as result. Because I
> initialize the result with []. With hasattr() I receive nothing. This means
> that some error must happened (I figured this out with all my other
> mistakes) :-). However which error? How to find the error?
> 

Hm

> >How do you call it from dtml?
> 
> I don't call it from dtml. The external method is a method of the ZClass
> itself. I index it in a Catalog. So no dtml calling from my point.

Ah, so I understand that it's not called with arguments. So you need
another external method.
Change you external method to look like this

def recursiveMethod(obj, result):
     if hasattr(obj, 'aq_parent'):
          result.append(obj.title)
          recursiveMethod(obj.aq_parent, result)
     return result


def ParentList(self):
    obj=self
    return recursiveMethod(obj, [])

Then make you external method refer to ParentList
This works without arguments from a testfolder. It should work from a
ZClass as well, but I did not test that.


> >If there is a traceback, it will show in the same way as normally, I
> >believe.
> 
> I don't know. I test it with a search on the catalog. I ask to show me all
> 'KBItem' types. It then shows all the values of the attributes of the KBItems.
> The values of the method are empty with hassattr().
> 

Ok, see if the above works then.

Rik