Exemple #1
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)
Exemple #2
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)