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

Sidnei da Silva sidnei@x3ng.com.br
Tue, 4 Feb 2003 06:47:13 -0500


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

Modified Files:
      Tag: paris-copypasterename-branch
	copy.py 
Log Message:
Fixing some imports. Need to cleanup ZopeContainerAdapter.rename()

=== Zope3/src/zope/app/copy.py 1.2 => 1.2.2.1 ===
--- Zope3/src/zope/app/copy.py:1.2	Tue Feb  4 04:58:28 2003
+++ Zope3/src/zope/app/copy.py	Tue Feb  4 06:46:41 2003
@@ -1,3 +1,4 @@
+from zope.app.traversing import getParent
 from zope.app.interfaces.copy import IObjectMover
 from zope.app.interfaces.copy import IObjectCopier
 
@@ -6,8 +7,8 @@
 
     __implements__ = IObjectMover
 
-    def __init__(self, container):
-        self.context = container
+    def __init__(self, object):
+        self.context = object
 
     def moveTo(target, name=None):
         '''Move this object to the target given.
@@ -15,9 +16,17 @@
         Returns the new name within the target
         Typically, the target is adapted to IPasteTarget.'''
 
-        object = self.context
-        if target.acceptsObject(object):
-            return target.pasteObject(object, name)
+        obj = self.context
+        if name is None:
+            name = objectName(obj)
+        movesource = getAdapter(getParent(obj), IMoveSource)
+        obj = movesource.removeObject(name, target)
+        pastetarget = getAdapter(target, IPasteTarget)
+        # publish an ObjectCreatedEvent (perhaps...?)
+        new_name = pastetarget.pasteObject(name, new_obj)
+        # call manage_afterAdd hook
+        # publish ObjectMovedEvent
+        return new_name
         
     def moveable():
         '''Returns True if the object is moveable, otherwise False.'''
@@ -29,14 +38,18 @@
         Returns True if it can be moved there. Otherwise, returns
         false.
         '''
-        return True
+        obj = self.context
+        if name is None:
+            name = objectName(obj)
+        pastetarget = getAdapter(target, IPasteTarget)
+        return pastetarget.acceptsObject(name, obj)
     
 class ObjectCopier:
 
     __implements__ = IObjectCopier
 
-    def __init__(self, container):
-        self.context = container
+    def __init__(self, object):
+        self.context = object
 
     def copyTo(target, name=None):
         """Copy this object to the target given.
@@ -49,9 +62,17 @@
         If a new object is created as part of the copying process, then
         an IObjectCreated event should be published.
         """
-        object = self.context
-        if target.acceptsObject(object):
-            return target.pasteObject(object, name)
+        obj = self.context
+        if name is None:
+            name = objectName(obj)
+        copysource = getAdapter(getParent(obj), ICopySource)
+        obj = copysource.copyObject(name, target)
+        pastetarget = getAdapter(target, IPasteTarget)
+        # publish an ObjectCreatedEvent (perhaps...?)
+        new_name = pastetarget.pasteObject(name, new_obj)
+        # call manage_afterAdd hook
+        # publish ObjectCopiedEvent
+        return new_name
 
     def copyable():
         '''Returns True if the object is copyable, otherwise False.'''
@@ -63,4 +84,8 @@
         Returns True if it can be copied there. Otherwise, returns
         False.
         '''
-        return True
+        obj = self.context
+        if name is None:
+            name = objectName(obj)
+        pastetarget = getAdapter(target, IPasteTarget)
+        return pastetarget.acceptsObject(name, obj)