R: [Zope] Discussion: Best practice site struture (LONG)

Luca Olivetti luca@wetron.es
Thu, 11 Apr 2002 11:33:28 +0200


Max M wrote:
> The correct way to ensure that there are no dangling relations naturally 
> is to create a method in any product being related to like (from the top 
> of my head)::
> 
>    def manage_beforeDelete(self):
>        self.relations.delete(self)


Yup, that's what I did as soon I discovered manage_beforeDelete.
But just to be sure I left the same call in my addObject method ;-)

And in the manage_beforeDelete of the referenced object I perform a check to see if the 
object is used by other objects, and raise a BeforeDeleteException[*] in that case (any 
other exception would be logged by zope but would not stop the deletion).

    def manage_beforeDelete(self):
         if self.relations.get(self):
             raise BeforeDeleteException, ('Object in use')


[*]in case it could be useful to someone else (to avoid some head banging ;-)

from OFS.ObjectManager import BeforeDeleteException

Bye

-- 
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007