Example #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)
Example #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)
Example #3
0
 def test_moveable(self):
     root = self.rootFolder
     container = traverse(root, 'folder1')
     container['file1'] = File()
     file = traverse(root, 'folder1/file1')
     mover = IObjectMover(file)
     self.failUnless(mover.moveable())
Example #4
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)
Example #5
0
 def test_moveableTo(self):
     #  A file should be moveable 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')
     mover = IObjectMover(file)
     self.failUnless(mover.moveableTo(container, 'file1'))
Example #6
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)
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
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))))
Example #11
0
    def cutObjects(self):
        """move 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 cut.")
            return

        container_path = zapi.getPath(self.context)

        # For each item, check that it can be moved; if so, save the
        # path of the object for later moving when a destination has
        # been selected; if not movable, provide an error message
        # explaining that the object can't be moved.
        items = []
        for id in ids:
            ob = self.context[id]
            mover = IObjectMover(ob)
            if not mover.moveable():
                m = {"name": id}
                title = getDCTitle(ob)
                if title:
                    m["title"] = title
                    self.error = _(
                        "Object '${name}' (${title}) cannot be moved",
                        mapping=m)
                else:
                    self.error = _("Object '${name}' cannot be moved",
                                   mapping=m)
                return
            items.append(zapi.joinPath(container_path, id))

        # store the requested operation in the principal annotations:
        clipboard = getPrincipalClipboard(self.request)
        clipboard.clearContents()
        clipboard.addItems('cut', items)