def test_copyfolderfromroot2(self): root = self.rootFolder target = traverse(root, '/folder2/folder2_1/folder2_1_1') source = traverse(root, '/folder1') copier = IObjectCopier(source) copier.copyTo(target) self.failUnless('folder1' in target)
def test_copyfolderfromroot(self): root = self.rootFolder target = traverse(root, '/folder2') source = traverse(root, '/folder1') copier = IObjectCopier(source) copier.copyTo(target) self.assertTrue('folder1' in target)
def copy_action(item, container): copier = IObjectCopier(item) try: copier.copyTo(container) return True except (KeyError, DuplicateIDError, InvalidItemType): return False
def copyObjects(self): """Copy objects specified in a list of object ids""" request = self.request ids = request.get('ids') if not ids: IStatusMessage(request).add( _("You didn't specify any ids to copy."), 'error') return container = self.context container_path = getPath(container) items = [] for id in ids: ob = container[id] copier = IObjectCopier(ob) if not copier.copyable(): IStatusMessage(request).add( _("Object '${name}' cannot be copied", {"name": id}), 'error' ) return items.append(joinPath(container_path, id)) # store the requested operation in the principal annotations: clipboard = getPrincipalClipboard(request) clipboard.clearContents() clipboard.addItems('copy', items) IStatusMessage(request).add(_('Selected items has been copied.'))
def handleCopy(self, action): if not len(self.selectedItems): self.status = self.copyNoItemsMessage return items = [] append = items.append for obj in self.selectedItems: __name__ = api.getName(obj) copier = IObjectCopier(obj) if not copier.copyable(): m = {"name": __name__} if __name__: m["name"] = __name__ self.status = _( "Object '${name}' (${name}) cannot be copied", mapping=m) else: self.status = _("Object '${name}' cannot be copied", mapping=m) transaction.doom() return append(api.joinPath(api.getPath(self.context), __name__)) self.status = self.copyItemsSelected # store the requested operation in the principal annotations: self.clipboard.clearContents() self.clipboard.addItems('copy', items)
def test_copyable(self): root = self.rootFolder container = traverse(root, 'folder1') container['file1'] = File() file = traverse(root, 'folder1/file1') copier = IObjectCopier(file) self.failUnless(copier.copyable())
def test_copytosame(self): root = self.rootFolder container = traverse(root, 'folder1') container['file1'] = File() file = traverse(root, 'folder1/file1') copier = IObjectCopier(file) copier.copyTo(container, 'file1') self.assertTrue('file1' in container) self.assertTrue('file1-2' in container)
def test_copyableTo(self): # A file should be copyable to a folder that has an # object with the same id. root = self.rootFolder container = traverse(root, 'folder1') container['file1'] = File() file = traverse(root, 'folder1/file1') copier = IObjectCopier(file) self.failUnless(copier.copyableTo(container, 'file1'))
def test_copytosamewithnewname(self): root = self.rootFolder container = traverse(root, 'folder1') container['file1'] = File() file = traverse(root, 'folder1/file1') copier = IObjectCopier(file) copier.copyTo(container, 'file2') self.failUnless('file1' in container) self.failUnless('file2' in container)
def test_copytootherwithnewname(self): root = self.rootFolder container = traverse(root, 'folder1') container['file1'] = File() target = traverse(root, 'folder2') file = traverse(root, 'folder1/file1') copier = IObjectCopier(file) copier.copyTo(target, 'file2') self.failUnless('file1' in container) self.failUnless('file2' in target)
def test_copytoother(self): root = self.rootFolder container = traverse(root, 'folder1') container['file1'] = File() target = traverse(root, 'folder2') file = traverse(root, 'folder1/file1') copier = IObjectCopier(file) copier.copyTo(target, 'file1') self.failUnless('file1' in container) self.failUnless('file1' in target)
def test_copytootherwithnewname(self): root = self.rootFolder container = traverse(root, 'folder1') container['file1'] = File() target = traverse(root, 'folder2') file = traverse(root, 'folder1/file1') copier = IObjectCopier(file) copier.copyTo(target, 'file2') self.assertTrue('file1' in container) self.assertTrue('file2' in target)
def test_copytootherwithnamecollision(self): root = self.rootFolder container = traverse(root, 'folder1') container['file1'] = File() target = traverse(root, 'folder2') target['file1'] = File() file = traverse(root, 'folder1/file1') copier = IObjectCopier(file) copier.copyTo(target, 'file1') # we do it twice, just to test auto-name generation copier.copyTo(target, 'file1') self.failUnless('file1' in container) self.failUnless('file1' in target) self.failUnless('file1-2' in target) self.failUnless('file1-3' in target)
def handlePaste(self, action): items = self.clipboard.getContents() moved = False not_pasteable_ids = [] for item in items: duplicated_id = False try: obj = api.traverse(self.context, item['target']) except TraversalError: pass else: if item['action'] == 'cut': mover = IObjectMover(obj) try: mover.moveTo(self.context) moved = True except DuplicateIDError: duplicated_id = True elif item['action'] == 'copy': copier = IObjectCopier(obj) try: copier.copyTo(self.context) except DuplicateIDError: duplicated_id = True else: raise if duplicated_id: not_pasteable_ids.append(api.getName(obj)) if moved: # Clear the clipboard if we do a move, but not if we only do a copy self.clipboard.clearContents() if not_pasteable_ids != []: # Show the ids of objects that can't be pasted because # their ids are already taken. # TODO Can't we add a 'copy_of' or something as a prefix # instead of raising an exception ? transaction.doom() raise UserError( _("The given name(s) %s is / are already being used" % ( str(not_pasteable_ids)))) else: # we need to update the table rows again, otherwise we don't # see the new item in the table self.updateAfterActionExecution() self.status = self.pasteSucsessMessage
def pasteable(self): """Decide if there is anything to paste """ target = self.context clipboard = getPrincipalClipboard(self.request) items = clipboard.getContents() for item in items: try: obj = traverse(target, item['target']) except TraversalError: pass else: if item['action'] == 'cut': mover = IObjectMover(obj) moveableTo = self.safe_getattr(mover, 'moveableTo', None) if moveableTo is None or not moveableTo(target): return False elif item['action'] == 'copy': copier = IObjectCopier(obj) copyableTo = self.safe_getattr(copier, 'copyableTo', None) if copyableTo is None or not copyableTo(target): return False else: raise return True
def pasteObjects(self): """Paste ojects in the user clipboard to the container """ target = self.context clipboard = getPrincipalClipboard(self.request) items = clipboard.getContents() moved = False not_pasteable_ids = [] for item in items: duplicated_id = False try: obj = traverse(target, item['target']) except TraversalError: pass else: if item['action'] == 'cut': mover = IObjectMover(obj) try: mover.moveTo(target) moved = True except DuplicateIDError: duplicated_id = True elif item['action'] == 'copy': copier = IObjectCopier(obj) try: copier.copyTo(target) except DuplicateIDError: duplicated_id = True else: raise if duplicated_id: not_pasteable_ids.append(getName(obj)) if moved: # Clear the clipboard if we do a move, but not if we only do a copy clipboard.clearContents() if not_pasteable_ids != []: # Show the ids of objects that can't be pasted because # their ids are already taken. # TODO Can't we add a 'copy_of' or something as a prefix # instead of raising an exception ? raise UserError( _("The given name(s) %s is / are already being used" % (str(not_pasteable_ids))))
def pasteObjects(self): """Paste ojects in the user clipboard to the container """ target = self.context clipboard = getPrincipalClipboard(self.request) items = clipboard.getContents() moved = False not_pasteable_ids = [] for item in items: duplicated_id = False try: obj = traverse(target, item['target']) except TraversalError: pass else: if item['action'] == 'cut': mover = IObjectMover(obj) try: mover.moveTo(target) moved = True except DuplicateIDError: duplicated_id = True elif item['action'] == 'copy': copier = IObjectCopier(obj) try: copier.copyTo(target) except DuplicateIDError: duplicated_id = True else: raise if duplicated_id: not_pasteable_ids.append(getName(obj)) if moved: # Clear the clipboard if we do a move, but not if we only do a copy clipboard.clearContents() if not_pasteable_ids != []: # Show the ids of objects that can't be pasted because # their ids are already taken. # TODO Can't we add a 'copy_of' or something as a prefix # instead of raising an exception ? raise UserError( _("The given name(s) %s is / are already being used" %( str(not_pasteable_ids))))
def pasteObjects(self): """Paste ojects in the user clipboard to the container """ target = self.context clipboard = getPrincipalClipboard(self.request) items = clipboard.getContents() moved = False not_pasteable_ids = [] for item in items: duplicated_id = False try: obj = traverse(target, item['target']) except TraversalError: pass else: if item['action'] == 'cut': mover = IObjectMover(removeAllProxies(obj)) try: mover.moveTo(target) moved = True except DuplicateIDError: duplicated_id = True elif item['action'] == 'copy': copier = IObjectCopier(removeAllProxies(obj)) try: copier.copyTo(target) except DuplicateIDError: duplicated_id = True except InvalidItemType: pass else: raise if duplicated_id: not_pasteable_ids.append(getName(obj)) if moved: clipboard.clearContents() if not_pasteable_ids: abort() IStatusMessage(self.request).add( _("The given name(s) %s is / are already being used" % ( str(not_pasteable_ids))), 'error')
def CopyAttachments(object, obevent): request = getRequest() if request is None: return if IContentEditorPreference(request.principal).editor != 'extjs': return data = obevent.data if data.format != 'zope.source.html': return ids = getUtility(IIntIds) if ids.queryId(object) is None: return res = splitText.split(data.text) if len(res) <= 1: return extension = IAttachmentsExtension(object) for idx in range(1, len(res)-1, 2): try: content = ids.queryObject(int(res[idx][26:-1])) if content is None: continue except: continue if content is \ removeAllProxies(extension.get(content.__name__)): continue copier = IObjectCopier(content) newName = copier.copyTo(extension) newContent = extension[newName] res[idx] = '%s%s"'%(res[idx][:26], ids.queryId(newContent)) data.text = u''.join(res)
def __bind__(self, content, globalenviron, environ): clone = super(IdColumn, self).__bind__(content, globalenviron, environ) table = self.table copier = IObjectCopier(content, None) if copier is not None and copier.copyable() and \ canAccess(table.context, '__setitem__') and \ not IUncopyableContent.providedBy(content): copyable = True table.supportsCopy = True else: copyable = False moveable = False renameable = False deletable = False if not IUnremoveableContent.providedBy(content): mover = IObjectMover(content, None) if mover is not None and mover.moveable(): if not IUnpastableContent.providedBy(content): moveable = True table.supportsCut = True if not IRenameNotAllowed.providedBy(content): renameable = \ not IContainerNamesContainer.providedBy(self.context) if renameable: table.supportsRename = True if not IUnremoveableContent.providedBy(content) and \ checkPermission('zojax.DeleteContent', content): deletable = True table.supportsDelete = True clone.buttons = copyable or moveable or renameable or deletable return clone
def copyObjects(self): """Copy objects specified in a list of object ids""" request = self.request ids = request.get('ids') if not ids: self.error = _("You didn't specify any ids to copy.") return container_path = getPath(self.context) # For each item, check that it can be copied; if so, save the # path of the object for later copying when a destination has # been selected; if not copyable, provide an error message # explaining that the object can't be copied. items = [] for id in ids: ob = self.context[id] copier = IObjectCopier(ob) if not copier.copyable(): m = {"name": id} title = getDCTitle(ob) if title: m["title"] = title self.error = _( "Object '${name}' (${title}) cannot be copied", mapping=m) else: self.error = _("Object '${name}' cannot be copied", mapping=m) return items.append(joinPath(container_path, id)) # store the requested operation in the principal annotations: clipboard = getPrincipalClipboard(self.request) clipboard.clearContents() clipboard.addItems('copy', items)
def copy_to(self, target, new_name=None, remove_permissions=True): return IObjectCopier(self).copyTo( target, new_name, remove_permissions=remove_permissions)