Пример #1
0
    def deleteElements(self, source_paths):
        sources = []
        for p in source_paths:
            if hasattr(p, "split"):
                p = p.split('/')
            if p:
                sources.append(p)

        # Replace with nulls to avoid changing indexes while deleting.
        orig_slots = {}
        try:
            for source in sources:
                slot = self.restrictedTraverse(source[:-1])
                assert ISlot.providedBy(slot), repr(slot)
                slot_id = id(aq_base(slot))
                if not orig_slots.has_key(slot_id):
                    orig_slots[slot_id] = slot
                nullify = guarded_getattr(slot, "nullify")  # Check security
                nullify(source[-1])
        finally:
            # Clear the nulls just added.
            for slot in orig_slots.values():
                slot.pack()
Пример #2
0
    def deleteElements(self, source_paths):
        sources = []
        for p in source_paths:
            if hasattr(p, "split"):
                p = p.split('/')
            if p:
                sources.append(p)

        # Replace with nulls to avoid changing indexes while deleting.
        orig_slots = {}
        try:
            for source in sources:
                slot = self.restrictedTraverse(source[:-1])
                assert ISlot.providedBy(slot), repr(slot)
                slot_id = id(aq_base(slot))
                if not orig_slots.has_key(slot_id):
                    orig_slots[slot_id] = slot
                nullify = guarded_getattr(slot, "nullify")  # Check security
                nullify(source[-1])
        finally:
            # Clear the nulls just added.
            for slot in orig_slots.values():
                slot.pack()
Пример #3
0
    def moveElements(self, source_paths, target_path, target_index, copy=0):
        """Moves or copies elements to a slot.
        """
        target_index = int(target_index)
        # Coerce the paths to sequences of path elements.
        if hasattr(target_path, "split"):
            target_path = target_path.split('/')
        sources = []
        for p in source_paths:
            if hasattr(p, "split"):
                p = p.split('/')
            if p:
                sources.append(p)

        # Ignore descendants when an ancestor is already listed.
        i = 1
        sources.sort()
        while i < len(sources):
            prev = sources[i - 1]
            if sources[i][:len(prev)] == prev:
                del sources[i]
            else:
                i = i + 1

        # Prevent parents from becoming their own descendants.
        for source in sources:
            if target_path[:len(source)] == source:
                raise CompositeError(
                    "Can't make an object a descendant of itself")

        # Gather the sources, checking interfaces and security before
        # making any changes.
        root = self.getPhysicalRoot()
        elements = []
        target = root.restrictedTraverse(target_path)
        assert ISlot.providedBy(target), repr(target)
        for source in sources:
            slot = root.restrictedTraverse(source[:-1])
            assert ISlot.providedBy(slot), repr(slot)
            element = slot.restrictedTraverse(source[-1])
            elements.append(element)
            if self._check_security:
                target._verifyObjectPaste(element)

        changed_slots = {}  # id(aq_base(slot)) -> slot
        try:
            if not copy:
                # Replace items with nulls to avoid changing indexes
                # while moving.
                for source in sources:
                    slot = root.restrictedTraverse(source[:-1])
                    slot_id = id(aq_base(slot))
                    if not changed_slots.has_key(slot_id):
                        changed_slots[slot_id] = slot
                    # Check security
                    nullify = guarded_getattr(slot, "nullify")
                    nullify(source[-1])

            # Add the elements and reorder.
            for element in elements:

                if not ICompositeElement.providedBy(element):
                    # Make a composite element wrapper.
                    element = CompositeElement(element.getId(), element)

                element = aq_base(element)
                new_id = target._get_id(element.getId())
                if copy:
                    element = copyOf(element)
                element._setId(new_id)
                target._setObject(new_id, element)
                # Check security
                reorder = guarded_getattr(target, "reorder")
                reorder(new_id, target_index)
                target_index += 1
        finally:
            # Clear the nulls just added.
            for slot in changed_slots.values():
                slot.pack()
Пример #4
0
    def moveElements(self, source_paths, target_path, target_index, copy=0):
        """Moves or copies elements to a slot.
        """
        target_index = int(target_index)
        # Coerce the paths to sequences of path elements.
        if hasattr(target_path, "split"):
            target_path = target_path.split('/')
        sources = []
        for p in source_paths:
            if hasattr(p, "split"):
                p = p.split('/')
            if p:
                sources.append(p)

        # Ignore descendants when an ancestor is already listed.
        i = 1
        sources.sort()
        while i < len(sources):
            prev = sources[i - 1]
            if sources[i][:len(prev)] == prev:
                del sources[i]
            else:
                i = i + 1

        # Prevent parents from becoming their own descendants.
        for source in sources:
            if target_path[:len(source)] == source:
                raise CompositeError(
                    "Can't make an object a descendant of itself")

        # Gather the sources, checking interfaces and security before
        # making any changes.
        root = self.getPhysicalRoot()
        elements = []
        target = root.restrictedTraverse(target_path)
        assert ISlot.providedBy(target), repr(target)
        for source in sources:
            slot = root.restrictedTraverse(source[:-1])
            assert ISlot.providedBy(slot), repr(slot)
            element = slot.restrictedTraverse(source[-1])
            elements.append(element)
            if self._check_security:
                target._verifyObjectPaste(element)

        changed_slots = {}  # id(aq_base(slot)) -> slot
        try:
            if not copy:
                # Replace items with nulls to avoid changing indexes
                # while moving.
                for source in sources:
                    slot = root.restrictedTraverse(source[:-1])
                    slot_id = id(aq_base(slot))
                    if not changed_slots.has_key(slot_id):
                        changed_slots[slot_id] = slot
                    # Check security
                    nullify = guarded_getattr(slot, "nullify")
                    nullify(source[-1])

            # Add the elements and reorder.
            for element in elements:

                if not ICompositeElement.providedBy(element):
                    # Make a composite element wrapper.
                    element = CompositeElement(element.getId(), element)

                element = aq_base(element)
                new_id = target._get_id(element.getId())
                if copy:
                    element = copyOf(element)
                element._setId(new_id)
                target._setObject(new_id, element)
                # Check security
                reorder = guarded_getattr(target, "reorder")
                reorder(new_id, target_index)
                target_index += 1
        finally:
            # Clear the nulls just added.
            for slot in changed_slots.values():
                slot.pack()