Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
0
 def move_to(self, target, new_name=None):
     return IObjectMover(self).moveTo(target, new_name)