> 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?
Consider using CheckoutableTemplates instead of templates as Zope objects. 
Gives you that filesystem-based-power they're all talking about PLUS
the ability to edit the template specifically or globally in the ZMI.

> 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.

No, use the 'aq_base'. Like this:

def _createImages(self, imageids):
      here_only = getattr(self, 'aq_base', self)
      for imageid in imageids:
          if not hasattr(here_only, imageid):

Peter Bengtsson, 
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
Zope maillist  -  Zope@zope.org
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to