[Zope] Extend copy/move protocol to object instantiation?
Brian Lloyd
Brian@digicool.com
Tue, 16 Feb 1999 17:08:16 -0500
> The copy/move protocol in 'CopySupport.py' is quite nice in that it
> allows the object which is being moved/copied to participate in the
> operation, including rejecting the operation or cleaning up at the
> conclusion of the operation. I found a need for something
> similar when
> objects are first installed in a folder(ish) location: 'scope out
> the neighborhood' and 'make yourself at home' hooks.
>
> -----------------------------------------------------
>
> class anyClass:
>
> ...
>
> def addsubs(self):
> '''add sub category field names'''
> resobj=self.aq_parent.catlist1()
> res =[]
> for field in resobj._searchable_result_columns():
> res.append(field)
> self.fields=res
>
> def makeyourselfathome(self):
> """parent specific installation hook"""
> self.addsubs()
>
> def addAnyClassObject(self,id,title,REQUEST=None):
> """Create an Object and install it in its parent Folder
> The argument 'self' will be bound to the parent Folder.
> """
> ob=anyClass(id)
> self._setObject(id, ob)
> ob.__of__(self).makeyourselfathome()
> if REQUEST is not None:
> return self.manage_main(self,REQUEST)
>
> -------------------------------------------------------------
>
> Would it make sense to add another 'op' type to
> CopySource._NotifyOfCopyTo() and CopySource._postCopy() to indicate a
> 'first home' operation?
>
> MAM
I'd much rather see an eventual Zope event model handle
things like this. In the absense of such a beast, we were
forced to come up with a workable solution for copy and paste,
but its probably not appropriate to try to make that general-
purpose.
I think it would be much better if you could eventually just
define "event handler" methods that interact with a well-known
event model to deal with such things, a la:
def onObjectAdd(self, event):
# Somehow use information in the event to
# do some fixup on the added object, etc.
...
def onCopyBegin(self, event):
...
def onCopyFinish(self, event):
...
Brian Lloyd brian@digicool.com
Software Engineer 540.371.6909
Digital Creations http://www.digicool.com