[Zope3-checkins] CVS: Zope3/src/zope/app - copy.py:1.2.2.3

Sidnei da Silva sidnei@x3ng.com.br
Tue, 4 Feb 2003 11:02:46 -0500


Update of /cvs-repository/Zope3/src/zope/app
In directory cvs.zope.org:/tmp/cvs-serv3317/src/zope/app

Modified Files:
      Tag: paris-copypasterename-branch
	copy.py 
Log Message:
Fixing some typos here and there

=== Zope3/src/zope/app/copy.py 1.2.2.2 => 1.2.2.3 ===
--- Zope3/src/zope/app/copy.py:1.2.2.2	Tue Feb  4 10:42:15 2003
+++ Zope3/src/zope/app/copy.py	Tue Feb  4 11:02:14 2003
@@ -1,7 +1,33 @@
-from zope.app.traversing import getParent
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from zope.app.traversing import getParent, objectName
 from zope.component import getAdapter
 from zope.app.interfaces.copy import IObjectMover
 from zope.app.interfaces.copy import IObjectCopier
+from zope.app.interfaces.container import IAddNotifiable
+from zope.app.interfaces.container import IDeleteNotifiable
+from zope.app.interfaces.container import IMoveNotifiable
+from zope.app.interfaces.container import ICopyNotifiable
+from zope.app.interfaces.container import IMoveSource
+from zope.app.interfaces.container import IPasteTarget
+from zope.app.interfaces.traversing import IPhysicallyLocatable
 
 class ObjectMover:
     '''Use getAdapter(obj, IObjectMover) to move an object somewhere.'''
@@ -18,15 +44,38 @@
         Typically, the target is adapted to IPasteTarget.'''
 
         obj = self.context
+        container = getParent(obj)
         if name is None:
             name = objectName(obj)
-        movesource = getAdapter(getParent(obj), IMoveSource)
+        
+        movesource = getAdapter(container, IMoveSource)
+        physicaltarget = getAdapter(target, IPhysicallyLocatable)
+        target_path = physicaltarget.getPhysicalPath()
+
+        physicalsource = getAdapter(container, IPhysicallyLocatable)
+        source_path = physicalsource.getPhysicalPath()
+        
+        if queryAdapter(obj, IMoveNotifiable):
+            getAdapter(obj, IMoveNotifiable).manage_beforeDelete(obj, container, \
+                                    movingTo=target_path)
+        elif queryAdapter(obj, IDeleteNotifiable):
+            getAdapter(obj, IDeleteNotifiable).manage_beforeDelete(obj, container)
+
         obj = movesource.removeObject(name, target)
         pastetarget = getAdapter(target, IPasteTarget)
         # publish an ObjectCreatedEvent (perhaps...?)
         new_name = pastetarget.pasteObject(name, new_obj)
+
         # call manage_afterAdd hook
+        if queryAdapter(obj, IMoveNotifiable):
+            getAdapter(obj, IMoveNotifiable).manage_afterAdd(obj, container, \
+                                movedFrom=source_path)
+        elif queryAdapter(obj, IAddNotifiable):
+            getAdapter(obj, IAddNotifiable).manage_afterAdd(obj, container)
+
         # publish ObjectMovedEvent
+        publish(container, ObjectMovedEvent(container))
+
         return new_name
         
     def moveable(self):
@@ -64,15 +113,33 @@
         an IObjectCreated event should be published.
         """
         obj = self.context
+        container = getParent(obj)
         if name is None:
             name = objectName(obj)
-        copysource = getAdapter(getParent(obj), ICopySource)
-        obj = copysource.copyObject(name, target)
+        
+        physicaltarget = getAdapter(target, IPhysicallyLocatable)
+        target_path = physicaltarget.getPhysicalPath()
+
+        physicalsource = getAdapter(container, IPhysicallyLocatable)
+        source_path = physicalsource.getPhysicalPath()
+        
+        copysource = getAdapter(container, ICopySource)
+        obj = copysource.copyObject(name, target_path)
+
         pastetarget = getAdapter(target, IPasteTarget)
         # publish an ObjectCreatedEvent (perhaps...?)
         new_name = pastetarget.pasteObject(name, new_obj)
+
         # call manage_afterAdd hook
-        # publish ObjectCopiedEvent
+        if queryAdapter(obj, ICopyNotifiable):
+            getAdapter(obj, ICopyNotifiable).manage_afterAdd(obj, container, \
+                                copiedFrom=source_path)
+        elif queryAdapter(obj, IAddNotifiable):
+            getAdapter(obj, IAddNotifiable).manage_afterAdd(obj, container)
+
+        # publish ObjectMovedEvent
+        publish(container, ObjectCopiedEvent(container))
+
         return new_name
 
     def copyable(self):