[Zope3-checkins] CVS: Zope3/src/zope/app/browser/container - rename.pt:1.2 contents.py:1.9
Sidnei da Silva
sidnei@x3ng.com.br
Tue, 11 Feb 2003 11:00:31 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/container
In directory cvs.zope.org:/tmp/cvs-serv3664/src/zope/app/browser/container
Modified Files:
contents.py
Added Files:
rename.pt
Log Message:
Merging paris-copypasterename-branch. Not very fun :(
=== Zope3/src/zope/app/browser/container/rename.pt 1.1 => 1.2 ===
--- /dev/null Tue Feb 11 11:00:31 2003
+++ Zope3/src/zope/app/browser/container/rename.pt Tue Feb 11 10:59:29 2003
@@ -0,0 +1,19 @@
+<html metal:use-macro="views/standard_macros/page">
+<body>
+ <div metal:fill-slot="body" >
+ <form method="POST" action="@@renameObjects.html">
+ <div tal:repeat="id request/ids">
+ <span>Name: <tal:block replace="id"/> </span>
+ <span>
+ New name:
+ <input type="hidden" name="ids:list" value=""
+ tal:attributes="value id" />
+ <input type="text" name="newids:list" value=""
+ tal:attributes="value id" />
+ </span>
+ </div>
+ <input type="submit" name="rename" value="rename" />
+ </form>
+ </div>
+</body>
+</html>
=== Zope3/src/zope/app/browser/container/contents.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/browser/container/contents.py:1.8 Fri Feb 7 10:48:37 2003
+++ Zope3/src/zope/app/browser/container/contents.py Tue Feb 11 10:59:29 2003
@@ -20,9 +20,16 @@
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):
@@ -61,6 +68,14 @@
info['size'] = sized_adapter
return info
+ def renameObjects(self, ids, newids):
+ """Given a sequence of tuples of old, new ids we rename"""
+ container = getAdapter(self.context, IZopeContainer)
+ for id, newid in zip(ids, newids):
+ if newid != id:
+ obj = container[id]
+ getAdapter(obj, IObjectMover).moveTo(container, newid)
+ self.request.response.redirect('@@contents.html')
def removeObjects(self, ids):
"""Remove objects specified in a list of object ids"""
@@ -70,12 +85,88 @@
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)
+ clipboard.clearContents()
+ 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)
+ clipboard.clearContents()
+ 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
+ target = container
+ physical = getAdapter(container, IPhysicallyLocatable)
+ container_path = physical.getPhysicalPath()
+
+ 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 hasClipboardContents(self):
+ """ interogates the PrinicipalAnnotation to see if
+ clipboard contents exist """
+
+ user = self.request.user
+
+ annotationsvc = getService(self.context, 'PrincipalAnnotation')
+ annotations = annotationsvc.getAnnotation(user)
+ clipboard = getAdapter(annotations, IPrincipalClipboard)
+
+ if clipboard.getContents():
+ return True
+
+ return False
+
+
def listContentInfo(self):
return map(self._extractContentInfo,
getAdapter(self.context, IZopeContainer).items())
contents = ViewPageTemplateFile('main.pt')
contentsMacros = contents
+
+ rename = ViewPageTemplateFile('rename.pt')
_index = ViewPageTemplateFile('index.pt')