예제 #1
0
    def test(self):
        input = [{
            'url': '/one/two/three/four'
        }, {
            'url': '/one/two'
        }, {
            'url': '/one/two/three'
        }, {
            'url': '/one/two/copy-of-three'
        }]

        expected = [{
            'url':
            '/one/two',
            'nodes': [{
                'url': '/one/two/three',
                'nodes': [{
                    'url': '/one/two/three/four',
                    'nodes': []
                }]
            }, {
                'url': '/one/two/copy-of-three',
                'nodes': []
            }]
        }]

        self.assert_json_equal(expected, make_tree_by_url(input))
예제 #2
0
    def _tree(self):
        subdossier_nodes = map(
            self._brain_to_node,
            self.context.get_subdossiers(sort_on='sortable_title',
                                         review_state=DOSSIER_STATES_OPEN))
        nodes = [self._context_as_node()] + subdossier_nodes

        return make_tree_by_url(nodes)
예제 #3
0
    def _tree(self):
        subdossier_nodes = map(
            self._brain_to_node,
            self.context.get_subdossiers(sort_on='sortable_title',
                                         review_state=DOSSIER_STATES_OPEN))
        nodes = [self._context_as_node()] + subdossier_nodes

        return make_tree_by_url(nodes)
예제 #4
0
    def __call__(self, expand=False):
        root_interface = self.get_root_interface()
        content_interfaces = self.get_content_interfaces()

        if self.request.form.get('include_root'):
            content_interfaces.append(root_interface)

        context = self.context

        if root_interface not in content_interfaces:
            while (not root_interface.providedBy(context)
                   and not IPloneSiteRoot.providedBy(context)):
                context = aq_parent(context)
        else:
            # This happens i.e. on lookup a dossier tree from a subdossier.
            #
            # The current context is the subdossier which is also
            # providing the root_interface. We have to get sure, that we return
            # the most upper object providing the given root_interface if
            # the root_interface is within `content_interfaces`
            current = context
            while (not IPloneSiteRoot.providedBy(current)):
                if root_interface.providedBy(current):
                    context = current
                current = aq_parent(current)

        if root_interface.providedBy(context):
            root = context
        else:
            roots = api.content.find(
                object_provides=root_interface.__identifier__)
            if roots:
                root = roots[0].getObject()
            else:
                root = None

        result = {
            'navigation': {
                '@id': '{}/@navigation'.format(root.absolute_url()),
            },
        }
        if not expand:
            return result

        items = api.content.find(
            object_provides=content_interfaces,
            path='/'.join(root.getPhysicalPath()),
            sort_on='sortable_title',
        )

        nodes = map(self.brain_to_node, items)
        result['navigation']['tree'] = make_tree_by_url(nodes)

        return result
예제 #5
0
    def __call__(self, expand=False):
        root_interface = self.get_root_interface()
        content_interfaces = self.get_content_interfaces()

        if self.request.form.get('include_root'):
            content_interfaces.append(root_interface)

        context = self.context

        if root_interface not in content_interfaces:
            while (not root_interface.providedBy(context)
                   and not IPloneSiteRoot.providedBy(context)):
                context = aq_parent(context)
        else:
            # This happens i.e. on lookup a dossier tree from a subdossier.
            #
            # The current context is the subdossier which is also
            # providing the root_interface. We have to get sure, that we return
            # the most upper object providing the given root_interface if
            # the root_interface is within `content_interfaces`
            current = context
            while (not IPloneSiteRoot.providedBy(current)):
                if root_interface.providedBy(current):
                    context = current
                current = aq_parent(current)

        if root_interface.providedBy(context):
            root = context
        else:
            roots = api.content.find(
                object_provides=root_interface.__identifier__)
            if roots:
                root = roots[0].getObject()
            else:
                root = None

        result = {
            'navigation': {
                '@id': '{}/@navigation'.format(root.absolute_url()),
            },
        }
        if not expand:
            return result

        items = api.content.find(
            object_provides=content_interfaces,
            path='/'.join(root.getPhysicalPath()),
            sort_on='sortable_title',
        )

        nodes = map(self.brain_to_node, items)
        result['navigation']['tree'] = make_tree_by_url(nodes)

        return result
예제 #6
0
    def test(self):
        input = [{'url': '/one/two/three/four'},
                 {'url': '/one/two'},
                 {'url': '/one/two/three'},
                 {'url': '/one/two/copy-of-three'}]

        expected = [
            {'url': '/one/two',
             'nodes': [
                    {'url': '/one/two/three',
                     'nodes': [
                            {'url': '/one/two/three/four',
                             'nodes': []}]},
                    {'url': '/one/two/copy-of-three',
                     'nodes': []}]}]

        self.assert_json_equal(expected, make_tree_by_url(input))