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)
 def test_movefolderfromroot(self):
     root = self.rootFolder
     target = traverse(root, '/folder2')
     source = traverse(root, '/folder1')
     mover = IObjectMover(source)
     mover.moveTo(target)
     self.assertTrue('folder1' in target)
Example #4
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 #5
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 #6
0
def move_action(item, container):
    mover = IObjectMover(item)
    try:
        mover.moveTo(container)
        return True
    except (KeyError, DuplicateIDError, InvalidItemType):
        return False
Example #7
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 #8
0
 def moveObject(self, msgHeader, msgOldparent,
                msgNewparent, msgObjectOid):
     """
     an object should be moved
     """
     print "moveObject"
     print "msgHeader: %s" % msgHeader
     print "msgOldparent: %s" % msgOldparent
     print "msgNewparent: %s" % msgNewparent
     print "msgObjectOid: %s" % msgObjectOid
     my_catalog = zapi.getUtility(ICatalog)
     newParentObj = None
     if not msgNewparent: # in root-folder of slave
         res = my_catalog.searchResults(oid_index=msgHeader['from_oid'])
         if len(res) > 0:
             newParentObj = iter(res).next()
     else:
         res = my_catalog.searchResults(oid_index=msgNewparent)
         if len(res) > 0:
             newParentObj = iter(res).next()
     objToMove = None
     res = my_catalog.searchResults(oid_index=msgObjectOid)
     if len(res) > 0:
         objToMove = iter(res).next()
     if objToMove and newParentObj:
         mover = IObjectMover(objToMove)
         if mover.moveableTo(newParentObj):
             mover.moveTo(newParentObj)
         else:
             raise Exception, "object not movable to new parent"
Example #9
0
    def cutObjects(self):
        """move 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 cut."), 'error')
            return

        container = self.context
        container_path = getPath(container)

        items = []
        for id in ids:
            ob = container[id]
            mover = IObjectMover(ob)
            if not mover.moveable():
                IStatusMessage(request).add(
                    _("Object '${name}' cannot be moved", {"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('cut', items)

        IStatusMessage(request).add(_('Selected items has been cut.'))
Example #10
0
    def handleCut(self, action):
        if not len(self.selectedItems):
            self.status = self.cutNoItemsMessage
            return

        items = []
        append = items.append
        for obj in self.selectedItems:
            mover = IObjectMover(obj)
            __name__ = api.getName(obj)
            if not mover.moveable():
                m = {"name": __name__}
                if name:
                    m["name"] = __name__
                    self.status = _(
                        "Object '${name}' (${name}) cannot be moved",
                        mapping=m)
                else:
                    self.status = _("Object '${name}' cannot be moved",
                                   mapping=m)
                transaction.doom()
                return
            append(api.joinPath(api.getPath(self.context), __name__))

        self.status = self.cutItemsSelected
        # store the requested operation in the principal annotations:
        self.clipboard.clearContents()
        self.clipboard.addItems('cut', items)
Example #11
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 #12
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), 1)
Example #13
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 #14
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 #15
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), 1)
Example #16
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 #17
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 #18
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)

        return mover.moveTo(self.container, newName)
Example #19
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), 2)
Example #20
0
 def test_AttributionUpToDateWhenCategoryMoved(self):
     """ Test if the attribution is up to date if a category was
     removed."""
     self.root['c'] = catable = Categorizable()
     attribution = interfaces.IAttribution(catable)
     attribution.attribute('cat11')
     from zope.copypastemove.interfaces import IObjectMover
     mover = IObjectMover(self.categories['set1']['cat11'])
     mover.moveTo(self.categories['set2'])
     self.assertTrue(attribution.isAttributed('cat11'))
Example #21
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 #22
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 #23
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), 2)
 def test_movetootherwithnewname(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, 'file2')
     self.assertFalse('file1' in container)
     self.assertTrue('file2' in target)
Example #25
0
    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
Example #26
0
    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
Example #27
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 = 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))))
Example #28
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 = 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))))
Example #29
0
 def test_IndexedUpToDateWhenCategoryMovedAndRenamed(self):
     """ Test if an attribution is indexed at all."""
     self.root['c'] = catable = Categorizable()
     attribution = interfaces.IAttribution(catable)
     attribution.attribute('cat11')
     zope.event.notify(ObjectModifiedEvent(catable))
     from zope.copypastemove.interfaces import IObjectMover
     mover = IObjectMover(self.categories['set1']['cat11'])
     mover.moveTo(self.categories['set2'], new_name='moved')
     zope.event.notify(ObjectModifiedEvent(catable))
     from z3c.indexer.query import AnyOf
     from z3c.indexer.search import SearchQuery
     query = SearchQuery(AnyOf('attribution-set', ('cat22', )))
     result = query.apply()
     self.assertTrue(len(result) == 0)
     query = SearchQuery(AnyOf('attribution-set', ('moved', )))
     result = query.apply()
     self.assertTrue(len(result) == 1)
Example #30
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 = 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')
Example #31
0
    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
Example #32
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 = 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(joinPath(container_path, id))

        # store the requested operation in the principal annotations:
        clipboard = getPrincipalClipboard(self.request)
        clipboard.clearContents()
        clipboard.addItems('cut', items)
Example #33
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 = 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(joinPath(container_path, id))

        # store the requested operation in the principal annotations:
        clipboard = getPrincipalClipboard(self.request)
        clipboard.clearContents()
        clipboard.addItems('cut', items)
Example #34
0
 def move_to(self, target, new_name=None):
     return IObjectMover(self).moveTo(target, new_name)