~jcsackett/charmworld/bac-tag-constraints

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Copyright 2012, 2013 Marco Ceppi, Canonical Ltd.  This software is
# licensed under the GNU Affero General Public License version 3 (see
# the file LICENSE).


def breadcrumbs(request):
    crumbs = []
    parts = filter(None, request.path_info.split("/"))
    if not len(parts) > 1:
        return []
    parts.insert(0, '')
    for i in range(1, len(parts)):
        if parts[i].lower() == 'hooks':
            crumbs.append({
                "url": u"/".join(parts[:i]),
                "name": "Hooks"
            })
        else:
            crumbs.append({"url": u"/".join(parts[: i + 1]),
                           "name": unicode(parts[i].replace(
                               "-", " ").replace("~", "").capitalize())})
    crumbs.insert(0, {'url': u'/', 'name': u'Home'})
    return crumbs


def sections(request):
    sections = [
        {
            "url": u"/",
            "name": u"Home",
            'active': False,
            'visible': False
        },
        {
            "url": u"/charms",
            "name": u"Charms",
            'active': False,
            'visible': True
        },
        {
            "url": u"/interfaces",
            "name": u"Interfaces",
            'active': False,
            'visible': True
        },
        {
            "url": u"/recently-changed",
            "name": u"Changes",
            'active': False,
            'visible': True
        },
        {
            "url": u"/tools",
            "name": u"Tools",
            'active': False,
            'visible': True
        },
    ]
    section = "/%s" % request.path_info[1:].split("/", 1)[0]
    # fix up oddballs
    if section.startswith("/~"):
        section = u"/charms"
    elif section == u"/interface-charm-map":
        section = u"/interfaces"
    for s in sections:
        if s['url'] == section:
            s['active'] = True
    # HACK for link to active series
    sections[1]['url'] = u'/charms/precise'
    return sections


def default_globals_factory(system):
    context, request = system['context'], system['request']

    return {
        'project': u'Charm Browser',
        'onload': u'',
        'breadcrumbs': breadcrumbs(request),
        'sections': sections(request)
    }