Beispiel #1
0
 def test_movefolderfromroot2(self):
     root = self.rootFolder
     target = traverse(root, '/folder2/folder2_1/folder2_1_1')
     source = traverse(root, '/folder1')
     mover = IObjectMover(source)
     mover.moveTo(target)
     self.failUnless('folder1' in target)
Beispiel #2
0
 def test_movefoldertosibling(self):
     root = self.rootFolder
     target = traverse(root, '/folder2')
     source = traverse(root, '/folder1/folder1_1')
     mover = IObjectMover(source)
     mover.moveTo(target)
     self.failUnless('folder1_1' in target)
Beispiel #3
0
 def test_movefoldertosame2(self):
     # Should be a noop, because "moving" to same location
     root = self.rootFolder
     target = traverse(root, '/folder1/folder1_1')
     source = traverse(root, '/folder1/folder1_1/folder1_1_1')
     mover = IObjectMover(source)
     mover.moveTo(target)
     self.failUnless('folder1_1_1' in target)
     self.assertEquals(len(target), 2)
Beispiel #4
0
 def test_movetosamewithnewname(self):
     root = self.rootFolder
     container = traverse(root, 'folder1')
     container['file1'] = File()
     file = traverse(root, 'folder1/file1')
     mover = IObjectMover(file)
     mover.moveTo(container, 'file2')
     self.failIf('file1' in container)
     self.failUnless('file2' in container)
Beispiel #5
0
    def renameItem(self, oldName, newName):
        object = self.container.get(oldName)
        if object is None:
            raise ItemNotFoundError(self.container, oldName)
        mover = IObjectMover(object)

        if newName in self.container:
            raise DuplicationError("%s is already in use" % newName)

        mover.moveTo(self.container, newName)
Beispiel #6
0
 def test_movetoother(self):
     root = self.rootFolder
     container = traverse(root, 'folder1')
     container['file1'] = File()
     target = traverse(root, 'folder2')
     file = traverse(root, 'folder1/file1')
     mover = IObjectMover(file)
     mover.moveTo(target, 'file1')
     self.failIf('file1' in container)
     self.failUnless('file1' in target)
Beispiel #7
0
 def test_movetosame(self):
     # Should be a noop, because "moving" to same location
     root = self.rootFolder
     container = traverse(root, 'folder1')
     container['file1'] = File()
     file = traverse(root, 'folder1/file1')
     mover = IObjectMover(file)
     mover.moveTo(container, 'file1')
     self.failUnless('file1' in container)
     self.assertEquals(len(container), 3)
Beispiel #8
0
    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 = zapi.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(zapi.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))))