Beispiel #1
0
def sidebar_menu(context):

    def traverse(tree, depth=1):
        ul = htmlutils.Tag('ul', classes={
            'nav', 'nav-pills', 'nav-stacked', 'depth-' + str(depth),
        })
        yield ul.start()
        for page, children in tree:
            is_active = page.pk == calling_page.pk

            li = htmlutils.Tag('li')
            li.toggle_class('active', is_active)

            yield li.start()

            if is_active:
                yield htmlutils.tag('a', page.title, href='#')
            else:
                yield htmlutils.tag('a', page.title, href=page.url)

            if children:
                yield from traverse(children, depth=depth + 1)

            yield li.end()
        yield ul.end()

    if 'self' in context:
        calling_page = context['self']
        top_menu_page = nav.get_top_menu_page(calling_page)
        if top_menu_page:
            descendants = top_menu_page.get_descendants().live().in_menu()
            tree = treeutils.grow_tree(descendants)
            return '\n'.join(traverse(treeutils.transform(tree)))
    return ''
Beispiel #2
0
def top_menu(context):
    pages = context['request'].site.root_page.get_children().live().in_menu()
    top_menu_page = nav.get_top_menu_page(context.get('self'))

    menu = []
    for page in pages:
        menu.append(MenuItem(
            page=page,
            active=(top_menu_page and top_menu_page.url == page.url),
        ))

    return {
        'menu': menu,
        'request': context['request'],  # required by the pageurl tag
    }
Beispiel #3
0
def top_menu(context):
    pages = context['request'].site.root_page.get_children().live().in_menu()
    top_menu_page = nav.get_top_menu_page(context.get('self'))

    menu = []
    for page in pages:
        menu.append(
            MenuItem(
                page=page,
                active=(top_menu_page and top_menu_page.url == page.url),
            ))

    return {
        'menu': menu,
        'request': context['request'],  # required by the pageurl tag
    }
Beispiel #4
0
def sidebar_menu(context):

    # pylint: disable=invalid-name
    def traverse(tree, depth=1):
        ul = htmlutils.Tag('ul',
                           classes={
                               'nav',
                               'nav-pills',
                               'nav-stacked',
                               'depth-' + str(depth),
                           })
        yield ul.start()
        for page, children in tree:
            is_active = page.pk == calling_page.pk

            li = htmlutils.Tag('li')
            li.toggle_class('active', is_active)

            yield li.start()

            if is_active:
                yield htmlutils.tag('a', page.title, href='#')
            else:
                yield htmlutils.tag('a', page.title, href=page.url)

            if children:
                yield from traverse(children, depth=depth + 1)

            yield li.end()
        yield ul.end()

    if 'self' in context:
        calling_page = context['self']
        top_menu_page = nav.get_top_menu_page(calling_page)
        if top_menu_page:
            descendants = top_menu_page.get_descendants().live().in_menu()
            tree = treeutils.grow_tree(descendants)
            return '\n'.join(traverse(treeutils.transform(tree)))
    return ''
Beispiel #5
0
    def test_get_top_menu_page(self):
        home = get_default_site().root_page
        treeutils.create_tree(home, [
            node('p1'), [
                node('p2'), [
                    node('p3', show_in_menus=False), [
                        node('p4', show_in_menus=False),
                    ],
                ],
            ],
        ])
        p1, (p2, (p3, (p4,))) = treeutils.grow_tree(home.get_descendants())

        self.assertEqual(nav.get_top_menu_page(None), None)
        self.assertEqual(nav.get_top_menu_page(home), None)
        self.assertEqual(nav.get_top_menu_page(p1).title, 'p1')
        self.assertEqual(nav.get_top_menu_page(p2).title, 'p1')
        self.assertEqual(nav.get_top_menu_page(p3).title, 'p1')
        self.assertEqual(nav.get_top_menu_page(p4).title, 'p1')
Beispiel #6
0
    def test_get_top_menu_page(self):
        home = get_default_site().root_page
        treeutils.create_tree(home, [
            node('p1'),
            [
                node('p2'),
                [
                    node('p3', show_in_menus=False),
                    [
                        node('p4', show_in_menus=False),
                    ],
                ],
            ],
        ])
        p1, (p2, (p3, (p4, ))) = treeutils.grow_tree(home.get_descendants())

        self.assertEqual(nav.get_top_menu_page(None), None)
        self.assertEqual(nav.get_top_menu_page(home), None)
        self.assertEqual(nav.get_top_menu_page(p1).title, 'p1')
        self.assertEqual(nav.get_top_menu_page(p2).title, 'p1')
        self.assertEqual(nav.get_top_menu_page(p3).title, 'p1')
        self.assertEqual(nav.get_top_menu_page(p4).title, 'p1')