Le lundi 07 janvier 2008 à 14:30 +0100, Tobias Rodäbel a écrit :
> Hi,
> I'd like to implement an event to be fired when an InternalPrincipal  
> shall be deleted from a PrincipalFolder.
> class IObjectShallBeDeletedEvent(IObjectEvent):
>       """Event, when an object will be deleted.
>       """
> class ObjectShallBeDeletedEvent(object):
>       """Event, when an object will be deleted.
>       """
>       implements(IObjectDeletedEvent)
>       def __init__(self, obj):
>               self.object = obj
> class MyPrincipal(InternalPrincipal):
>       def __del__(self):
>               notify(ObjectShallBeDeletedEvent(self))
>               super(MyObject, self).__del__()
> Because of some reason my event will not be fired. Did I miss something?
> For now I implemented this by subclassing PrincipalFolder and adding  
> my notify call to the __delitem__ method. That works well. But I would  
> prefer an implementation like drafted above.


Maybe I'm wrong, but I thing that '__del__' destructor is not called
when an object is removed from it's container, but when it's references
count in Python interpretor is decremented to 0.

For your use case, the only thing you should do is just to implement a
subscriber to IObjectRemovedEvent (defined into
zope.app.container.interfaces) which is automatically fired by all
"standard" Zope3 containers.

Hope this helps,

  Thierry Florac
  Chef de projet intranet/internet
  Office National des Forêts - Département Informatique
  2, Avenue de Saint-Mandé
  75570 PARIS Cedex 12
  Tél. : +33
  Fax. : +33

Zope3-users mailing list

Reply via email to