Example #1
0
 def previewElement(self, path, RESPONSE):
     """Redirects to the preview for an element.
     """
     root = self.getPhysicalRoot()
     obj = root.restrictedTraverse(path)
     if ICompositeElement.providedBy(obj):
         obj = obj.dereference()
     RESPONSE.redirect(obj.absolute_url())
Example #2
0
 def showElement(self, path, RESPONSE):
     """Redirects to the workspace for an element.
     """
     root = self.getPhysicalRoot()
     obj = root.restrictedTraverse(path)
     if ICompositeElement.providedBy(obj):
         obj = obj.dereference()
     RESPONSE.redirect("%s/%s" % (
         obj.absolute_url(), self.workspace_view_name))
Example #3
0
 def changeTemplate(self, paths, template, reload=0, close=1, REQUEST=None):
     """Changes the template for objects.
     """
     info = self.getTemplateChangeInfo(paths)
     if template not in info["templates"]:
         raise KeyError("Template %s is not among the choices" % template)
     tool = aq_parent(aq_inner(self))
     for ob in info["obs"]:
         assert ICompositeElement.providedBy(ob)
         m = guarded_getattr(ob, "setInlineTemplate")
         m(template)
     if REQUEST is not None:
         if reload:
             REQUEST["RESPONSE"].redirect(REQUEST["HTTP_REFERER"])
         elif close:
             return close_dialog_html
Example #4
0
    def renderToList(self, allow_add):
        """Renders the items to a list.
        """
        res = ['<div class="slot_header"></div>']
        composite = aq_parent(aq_inner(aq_parent(aq_inner(self))))
        editing = composite.isEditing()
        items = self.objectItems()
        if editing:
            mypath = escape('/'.join(self.getPhysicalPath()))
            myid = self.getId()
            if hasattr(self, 'portal_url'):
                icon_base_url = self.portal_url()
            else:
                request = getattr(self, 'REQUEST', None)
                if request is not None:
                    icon_base_url = request['BASEPATH1']
                else:
                    icon_base_url = '/'

        if editing and allow_add:
            res.append(self._render_add_target(myid, 0, mypath))

        for index in range(len(items)):
            name, obj = items[index]

            try:
                assert ICompositeElement.providedBy(obj), (
                    "Not a composite element: %s" % repr(obj))
                text = obj.renderInline()
            except ConflictError:
                # Ugly ZODB requirement: don't catch ConflictErrors
                raise
            except:
                text = formatException(self, editing)


            if editing:
                res.append(self._render_editing(obj, text, icon_base_url))
            else:
                res.append(view_tag % text)
            
            if editing and allow_add:
                res.append(self._render_add_target(myid, index+1, mypath, obj.getId()))

        return res
    def renderIterator(self, allow_add=True):
        """Iterates over the items rendering one item for each element.
        
        Does minimal decoration of the rendered content.
        Exactly one yield for each item (including add/edit controls where required).
        If allow_add there will be one additional item yielded for the final add.
        """
        composite = aq_parent(aq_inner(aq_parent(aq_inner(self))))
        editing = composite.isEditing()
        items = self.objectItems()
        if editing:
            mypath = escape('/'.join(self.getPhysicalPath()))
            myid = self.getId()
            if hasattr(self, 'portal_url'):
                icon_base_url = self.portal_url()
            elif hasattr(self, 'REQUEST'):
                icon_base_url = self.REQUEST['BASEPATH1']
            else:
                icon_base_url = '/'

        for index, (name, obj) in enumerate(items):

            try:
                assert ICompositeElement.isImplementedBy(obj), (
                    "Not a composite element: %s" % repr(obj))
                text = obj.renderInline()
            except ConflictError:
                # Ugly ZODB requirement: don't catch ConflictErrors
                raise
            except:
                text = formatException(self, editing)

            if editing:
                if allow_add:
                    add = target_tag % (myid, index, mypath, index)
                else:
                    add = ''
                yield add + self._render_editing(obj, text, icon_base_url)
            else:
                yield text

        if editing and allow_add:
            index = len(items)
            yield target_tag % (myid, index, mypath, index)
    def renderIterator(self, allow_add=True):
        """Iterates over the items rendering one item for each element.
        
        Does minimal decoration of the rendered content.
        Exactly one yield for each item (including add/edit controls where required).
        If allow_add there will be one additional item yielded for the final add.
        """
        composite = aq_parent(aq_inner(aq_parent(aq_inner(self))))
        editing = composite.isEditing()
        items = self.objectItems()
        if editing:
            mypath = escape('/'.join(self.getPhysicalPath()))
            myid = self.getId()
            if hasattr(self, 'portal_url'):
                icon_base_url = self.portal_url()
            elif hasattr(self, 'REQUEST'):
                icon_base_url = self.REQUEST['BASEPATH1']
            else:
                icon_base_url = '/'

        for index, (name, obj) in enumerate(items):

            try:
                assert ICompositeElement.isImplementedBy(obj), (
                    "Not a composite element: %s" % repr(obj))
                text = obj.renderInline()
            except ConflictError:
                # Ugly ZODB requirement: don't catch ConflictErrors
                raise
            except:
                text = formatException(self, editing)

            if editing:
                if allow_add:
                    add = target_tag % (myid, index, mypath, index)
                else:
                    add = ''
                yield add + self._render_editing(obj, text, icon_base_url)
            else:
                yield text

        if editing and allow_add:
            index = len(items)
            yield target_tag % (myid, index, mypath, index)
Example #7
0
 def getTemplateChangeInfo(self, paths):
     """Returns information for changing the template applied to objects.
     """
     root = self.getPhysicalRoot()
     tool = aq_parent(aq_inner(self))
     obs = []
     all_choices = None  # {template -> 1}
     current = None
     for path in str(paths).split(':'):
         ob = root.unrestrictedTraverse(path)
         obs.append(ob)
         if not ICompositeElement.providedBy(ob):
             raise ValueError("Not a composite element: %s" % path)
         m = guarded_getattr(ob, "queryInlineTemplate")
         template = m()
         if current is None:
             current = template
         elif current and current != template:
             # The current template isn't the same for all of the elements,
             # so there is no common current template.  Spell this condition
             # using a non-string value.
             current = 0
         m = guarded_getattr(ob, "listAllowableInlineTemplates")
         templates = m()
         d = {}
         for name, template in templates:
             d[name] = template
         if all_choices is None:
             all_choices = d
         else:
             for template in all_choices.keys():
                 if not d.has_key(template):
                     del all_choices[template]
     return {
         "obs": obs,
         "templates": all_choices,
         "current_template": current,
         }
Example #8
0
File: tool.py Project: goschtl/zope
    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()
Example #9
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()