[Zope] manage_afterAdd quirks

Philip Jägenstedt philip at lysator.liu.se
Thu Aug 18 19:25:22 EDT 2005


Hello!

I'm trying to write a small filesystems based product which I'm calling
MovieWorld. The main class (MovieWorld) inherits from ObjectManager and
is to be configured to contain a folder with images and a index_html
page template (so that it can be edited via ZMI if needed). Setting
these things up in a manage_afterAdd works fine as long as I'm just
adding new products, but renaming or copying will cause manage_afterAdd
to be called again, which fails because the objects to be created
already exist. What should I do?

The obvious solution is to check for existance of the objects and only
add them if they don't exist, which is what I tried. This worked for the
folder called "images", but I was using hasattr(self,'images') to check
to existance, so it worked by coincidence. What I mean is it works only
if there is no object called images aquired, which means it also mus not
exist anywhere along the aquire path. For this reason,
hasttr(self,'index_html') will return true, and the index_html template
will not be added at all.

It seems I need one of three things:

1. A better way to add images and a template altogether.
2. A hook which is only called once, when the object is first created.
3. A method to check if the objects exist in the newly added item
directly, not aquired.

Help!

// Philip Jägenstedt



More information about the Zope mailing list