[Zope-dev] urg
Tom Deprez
tom.deprez@uz.kuleuven.ac.be
Tue, 07 Mar 2000 10:47:58 +0100
Hi Rik,
Yes, thanks for replying! Getting non-experts replies is better then
getting none because otherwise it looks like you're alone on Zope world.
Ok, I'll tell you something more :
I've created a ZClass with as base class CatalogAware.
The external method just contains what I wrote below. In the ZClass method
tab, I create a new method (manage_afterAdd) which points to this external
method.
So when a ZClass instance is added or moved, the manage_afterAdd method
should be executed.
>If you want to use CatalogAware from an external method, you have to
>import it.
I did, but perhaps here is the mistake. Here is my full python script (and
my first).
import sys
sys.path.append('usr/local/zope/lib/python/Products/ZCatalog')
import CatalogAwareness
""" CatalogAwareness contains the CatalogAware Class """
def manage_afterAdd(self,item,container)
item.myparent=container.id
CatalogAware.manage_afterAdd(self,item,container)
return
I also tried this, but it always gives the same error :
def manage_afterAdd(self,item,container)
import sys
sys.path.append('usr/local/zope/lib/python/Products/ZCatalog')
import CatalogAwareness
item.myparent=container.id
CatalogAware.manage_afterAdd(self,item,container)
return
I'll look at the boring product.
Thanks,
Tom.
At 10:26 07/03/2000 +0100, Rik Hoekstra wrote:
>
>
>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
>