[Zope-dev] urg

Rik Hoekstra rik.hoekstra@inghist.nl
Tue, 07 Mar 2000 10:26:48 +0100


Tom Deprez wrote:
> 
> Damn, I'm loosing my faith in Zope. I'm already 3 days trying to find a
> solution, but I'm still at the same place as I was 3 days ago. This isn't
> funny anymore.
> 
> You're my last resort, I hope someone can help.
> 
> I'm trying to create a ZClass which updates some properties when it is
> added or moved. Now, people pointed me to the manage_afterAdd method. And
> indeed, when I use this code  (as an external method) :
> 
> def manage_afterAdd(self,item,container)
>    item.myparent=container.id
>    return
> 
> it works when I don't have a class which inherits from CatalogAware Class.
> However, it doesn't works with a class inherited from CatalogAware Class.
> Probably because the manage_afterAdd method is defined in the CatalogAware
> Class.
> 
> So I tried to modify the external method to :
> 
> def manage_afterAdd(self,item,container)
>    item.myparent=container.id
>    CatalogAware.manage_afterAdd(self,item,container)
>    return
> 
> But then I get following error when adding an instance of the new class :
> 
> Zope Error
> 
>            Zope has encountered an error while publishing this resource.
> 
>            Error Type: NameError
>            Error Value: CatalogAware
> 
>            Troubleshooting Suggestions
> 
>                 This resource may be trying to reference a nonexistent
> object or variable
>                 CatalogAware.
>                 The URL may be incorrect.
>                 The parameters passed to this resource may be incorrect.
>                 A resource that this resource relies on may be encountering
> an error.
> 
> Urgh, I'm really desperate. Do you know what I'm doing wrong?
> 
> ps. Why does this function has to be an external method? Is it also
> possible with an DTML method?

Tom, 

I do not claim to be an expert on these items, so please bear with me.
Most of my knowledge is theoretical, but since no one else steps in, a
non-expert answer is better than none at all I suppose (and who knows
what other responses my blundering invokes ;-)

A few remarks: Your external method doesn't define a new class? It
shouldn't, because I believe Zope prevents you from doing it, and if you
could, it is looked upon as bad practice.
A function can't (in itself) override a class method. You should
override it in a subclass from CatalogAware. 
But we are talking python products here or python base classes for
ZClasses, and I'm not sure you want that. If so, look at the Boring
Product for a general introduction.

Some more points:
If you want to use CatalogAware from an external method, you have to
import it. Did you do that in your method? (that's not clear from your
posts now)

You can't do this in a DTML Method, and not even in a PythonMethod,
though there may be ways around this last one with XXXPythonMethods.
External Methods are plain python, but with a Zope twist that prevents
them from doing certain things.

HTH

Rik