[Zope-dev] manage_afterAdd and manage_beforeDelete
Brian Lloyd
Brian@digicool.com
Mon, 12 Jul 1999 11:52:40 -0400
> >Well, technically there is a constructor of sorts - the DTML method
> >or External method that is the target of the "Add" form for your
> >ZClass is basically the equivalent of a Python constructor
>
> I've been adding a method to my ZClasses called
> 'manage_afterAdd' (and often, 'manage_beforeDelete'), which
> are called by the ZClass framework, I think. It's really
> convenient, but I'm not entierly sure they're not reserved
> for internal uses. I haven't found anything that uses them yet.
>
> Mike Pelletier.
(I've CC'ed the lists on this, since it probably of interest
to other folks out there...)
Mike,
It probably a bad idea to try to use manage_afterAdd
as a handy constructor - the manage_afterAdd and manage_beforeDelete
methods are currently a lightweight solution for the fact that
there is no "event model" in Zope, but often objects will want
to perform some extra activities when they are added/deleted
(such as add or remove themselves from Catalogs).
The manage_afterAdd, in particular, could get you in trouble,
since it will also be called whenever an object cut/copied and
pasted to a new location. In that case the construction logic
would almost certainly not be appropriate, and could actually
run without raising an error, but re-initializing and wiping out
the existing data in your object in the process. :(
In general, the manage_afterAdd and manage_beforeDelete protocol
should be thought of as hooks for fixing up or cleaning up the
environment of an object on add/delete/cut/copy/paste events
(registering and unregistering with Catalogs, etc.).
Brian Lloyd brian@digicool.com
Software Engineer 540.371.6909
Digital Creations http://www.digicool.com