Example #1
0
    def test_published(self, client):
        """ content that's in navigation but not published """
        root = Node.root()
        testable = root.add("sub")
        child = testable.add("child")
        content = Type1(node=child, navigation=True, state="published")
        content.save()

        assert get_visible_children(testable).count() == 1
        assert get_visible_children(testable).get() == content.node
Example #2
0
def topnav(context):
    node = context.get('instance')
    request = context.get('request')
    language = get_active_language(request)

    nav = []

    ## Find top/secondlevel published nodes in one query XXX
    for toplevel in queries.toplevel_visible_children(language=language):
        ## make sure /foo/bar does not match in /football by adding the /
        item = dict(active=False, node=toplevel)
        content = toplevel.content(language=language)
        item['url'] = toplevel.get_absolute_url(language=language)
        item['title'] = content.title if content else ""

        if toplevel == node or \
           (node and node.path.startswith(toplevel.path + '/')):
            item['active'] = True

        sub = []
        for secondlevel in queries.get_visible_children(toplevel, language=language):
            slitem = dict(node=secondlevel)
            content = secondlevel.content(language=language)
            slitem['url'] = secondlevel.get_absolute_url(language=language)
            slitem['title'] = content.title if content else ""

            sub.append(slitem)

        item['sub'] = sub
        nav.append(item)
    return dict(toplevel=nav)
Example #3
0
    def test_not_visible(self, client):
        """ content that's published but not in navigation """
        root = Node.root()
        testable = root.add("sub")
        child = testable.add("child")
        content = Type1(node=child, state="published")
        content.save()

        assert get_visible_children(testable).count() == 0
Example #4
0
    def test_mix(self, client):
        """ a mix of types and states """
        root = Node.root()
        testable = root.add("sub")
        ch1 = Type1(node=testable.add("ch1"), navigation=True,
                    state="published").save()
        ch2 = Type1(node=testable.add("ch2"), navigation=False,
                    state="published").save()
        ch3 = Type2(node=testable.add("ch3"), navigation=True,
                    state="published").save()
        ch4 = Type1(node=testable.add("ch4"), navigation=True,
                    state="private").save()
        ch5 = Type1(node=testable.add("ch5"), navigation=True,
                    state="published").save()

        visible = list(get_visible_children(testable))
        assert visible == [ch1.node, ch3.node, ch4.node, ch5.node]
Example #5
0
def navigation_items(request, node):
    language = get_active_language()

    nav = []

    ## remove visible_children? Unnecessary with permission checks

    ## Find top/secondlevel published nodes in one query XXX
    for toplevel in queries.toplevel_visible_children(language=language):
        ## make sure /foo/bar does not match in /football by adding the /
        item = dict(active=False, node=toplevel)
        content = toplevel.content(language=language)

        if content:
            spoke = content.spoke()
            perm = spoke.permissions.get('view')
            if not auth.has_access(request, spoke, spoke, perm):
                continue

        item['url'] = toplevel.get_absolute_url(language=language)
        item['title'] = content.title if content else ""

        if toplevel == node or \
           (node and node.path.startswith(toplevel.path + '/')):
            item['active'] = True

        sub = []
        for secondlevel in queries.get_visible_children(toplevel, language=language):
            slitem = dict(node=secondlevel)
            content = secondlevel.content(language=language)
            spoke = content.spoke()
            perm = spoke.permissions.get('view')
            if not auth.has_access(request, spoke, spoke, perm):
                continue

            slitem['url'] = secondlevel.get_absolute_url(language=language)
            slitem['title'] = content.title if content else ""

            sub.append(slitem)

        item['sub'] = sub
        nav.append(item)
    return dict(toplevel=nav)
Example #6
0
 def test_empty(self, client):
     """ a node without any children """
     root = Node.root()
     testable = root.add("sub")
     assert get_visible_children(testable).count() == 0