[Zope] External Method 3
Rik Hoekstra
rik.hoekstra@inghist.nl
Wed, 29 Mar 2000 11:42:57 +0200
Tom Deprez wrote:
>
> Ok, now I found the error. The error must be in the while loop, where we
> say 'iterate until the obj = None'. However 'None' is never reached... (I
> guess).
> The following code works, but I this isn't at all a good solution.
>
> Can someone tell me how I can safely test that the current object is the
> first object in the object database. In other laguages you can test this
> with 'nil'. How can I test this within Zope? Please, tell me!
>
Hm, is it - if it's undefined?
what about (taking the function from one of your previouw posts) (only
lightly tested):
def recursiveMethod(self, obj, result):
try:
if obj.aq_parent:
result.append(obj.title)
recursiveMethod(self, obj.aq_parent, result)
except AttributeError:
pass
return result
This is less elegant than testing for the attribute aq_parent, but
either hasattr is not allowed for External Methods, or ac_parent is not
an attribute.
Note, however, that if an object has no title it may also throw in an
AttributeError, thus aborting your method in too early. You could try
and catch this exception separately, but perhaps it shouldn't happen
anyway.
Rik