Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
def copy_action(item, container):
    copier = IObjectCopier(item)
    try:
        copier.copyTo(container)
        return True
    except (KeyError, DuplicateIDError, InvalidItemType):
        return False
Exemplo n.º 4
0
    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.'))
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
 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())
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
 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'))
Exemplo n.º 9
0
 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'))
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
 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)
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 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)
Exemplo n.º 14
0
 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)
Exemplo n.º 15
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
Exemplo n.º 16
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
Exemplo n.º 17
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))))
Exemplo n.º 18
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))))
Exemplo n.º 19
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')
Exemplo n.º 20
0
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)
Exemplo n.º 21
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
Exemplo n.º 22
0
    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)
Exemplo n.º 23
0
    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)
Exemplo n.º 24
0
 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)
Exemplo n.º 25
0
 def copy_to(self, target, new_name=None, remove_permissions=True):
     return IObjectCopier(self).copyTo(
         target, new_name, remove_permissions=remove_permissions)