Ejemplo n.º 1
0
def get_navigation(request):
    segments = request.url.path_segments
    C = request.environ['couchish']
    with C.session() as S:
        pages = list(S.view('page/by_segments'))
    count = 0
    lastparent = []
    sitemap = []
    for page in pages:
        if page.key != [""]:
            key = 'root.' + '.'.join(page.key)
        else:
            key = 'root'
        parent = key.split('.')[:-1]
        if parent == lastparent:
            count += 1
        else:
            count = 1
            lastparent = parent
        node = [key,page.value['title'], count, {}]
        sitemap.append(node)
    sitemap.extend(get_workshop_nodes(C))
    sitemap.extend(get_news_nodes(C))
    sitemap.extend(get_events_nodes(C))
    return create_sitemap(sitemap)
Ejemplo n.º 2
0
 def test_yaml(self):
     sitemap_yaml = """
     - [root, Home, 1, {}]
     - [root.about, About, 2, {}]
     - [root.gallery, Gallery, 3, {}]
     """
     sitemap = create_sitemap(yaml.load(sitemap_yaml))
     html = Navigation(showroot=True, item_class=['firstlast','number'], item_id=None).render_navigation(sitemap, self.request)
     assert html == '<ul><li id="nav-root" class="first-child item-1"><a href="/">Home</a></li><li id="nav-about" class="item-2"><a href="/about">About</a></li><li class="selected last-child item-3" id="nav-gallery"><a href="/gallery">Gallery</a></li></ul>'