[Zope3-checkins] CVS: Zope3/src/zope/app/browser/container - contents.py:1.7.2.1

Sidnei da Silva sidnei@x3ng.com.br
Wed, 5 Feb 2003 07:43:29 -0500


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

Modified Files:
      Tag: paris-copypasterename-branch
	contents.py 
Log Message:
Trying to get physically located :P

=== Zope3/src/zope/app/browser/container/contents.py 1.7 => 1.7.2.1 ===
--- Zope3/src/zope/app/browser/container/contents.py:1.7	Fri Jan 31 05:51:45 2003
+++ Zope3/src/zope/app/browser/container/contents.py	Wed Feb  5 07:42:57 2003
@@ -20,9 +20,15 @@
 from zope.app.interfaces.size import ISized
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 
-from zope.component import queryView, queryAdapter,  getAdapter
+from zope.component import queryView, queryAdapter, getAdapter, getService
+from zope.app.interfaces.services.principalannotation import IPrincipalAnnotationService
 from zope.publisher.browser import BrowserView
-
+from zope.app.interfaces.traversing import IPhysicallyLocatable
+from zope.app.traversing import traverse, getPhysicalRoot
+from zope.app.interfaces.copy import IPrincipalClipboard
+from zope.app.interfaces.container import IPasteTarget
+from zope.app.interfaces.copy import IObjectCopier
+from zope.app.interfaces.copy import IObjectMover
 
 class Contents(BrowserView):
 
@@ -68,6 +74,63 @@
         for id in ids:
             container.__delitem__(id)
 
+        self.request.response.redirect('@@contents.html')
+
+    def copyObjects(self, ids):
+        """Copy objects specified in a list of object ids"""
+        physical = getAdapter(self.context, IPhysicallyLocatable)
+        container_path = physical.getPhysicalPath()
+        
+        user = self.request.user
+        annotationsvc = getService(self.context, 'PrincipalAnnotation')
+        annotations = annotationsvc.getAnnotation(user)
+        clipboard = getAdapter(annotations, IPrincipalClipboard)
+        items = []
+        for id in ids:
+            items.append('%s/%s' % ('/'.join(container_path), id))
+        clipboard.addItems('copy', items)
+
+        self.request.response.redirect('@@contents.html')
+
+    def cutObjects(self, ids):
+        """move objects specified in a list of object ids"""
+        physical = getAdapter(self.context, IPhysicallyLocatable)
+        container_path = physical.getPhysicalPath()
+        
+        user = self.request.user
+        annotationsvc = getService(self.context, 'PrincipalAnnotation')
+        annotations = annotationsvc.getAnnotation(user)
+        clipboard = getAdapter(annotations, IPrincipalClipboard)
+        items = []
+        for id in ids:
+            items.append('%s/%s' % ('/'.join(container_path), id))
+        clipboard.addItems('cut', items)
+        
+        self.request.response.redirect('@@contents.html')
+
+    def pasteObjects(self):
+        '''Iterate over clipboard contents and perform the move/copy operations'''
+        container = self.context
+        physical = getAdapter(container, IPhysicallyLocatable)
+        container_path = physical.getPhysicalPath()
+        root = getPhysicalRoot(container)
+        container = traverse(root, container_path)
+        target = getAdapter(container, IPasteTarget)
+
+        user = self.request.user
+        annotationsvc = getService(self.context, 'PrincipalAnnotation')
+        annotations = annotationsvc.getAnnotation(user)
+        clipboard = getAdapter(annotations, IPrincipalClipboard)
+        items = clipboard.getContents()
+        for item in items:
+            obj = traverse(container, item['target'])
+            if item['action'] == 'cut':
+                getAdapter(obj, IObjectMover).moveTo(target)
+            elif item['action'] == 'copy':
+                getAdapter(obj, IObjectCopier).copyTo(target)
+            else:
+                raise
+        
         self.request.response.redirect('@@contents.html')
 
     def listContentInfo(self):