Example #1
0
def navbar(request):
    """adds the variable 'navbar' to the context"
    """
    navbar = get_navbar(request.user)
    for ent in navbar:
        ent.selected = request.path.startswith(ent.url)
    return {'navbar': navbar}
def crumbs(request):
    """adds the path 'crumbs'
    crumbs have the format of:
    [ {'name': 'foo',  'path': '/foo'},
      {'name': 'bar',  'path': '/foo/bar'},
      {'name': 'bing', 'path': '/foo/bar/bing'} ]
    """
    rooturl = getattr(settings, 'ROOT_URL', '')
    assert(request.path.startswith(rooturl))
    if request.path != '/':
        # split the path into the names /name1/name2/name3
        crumb_names = request.path.strip('/').split('/')
    else:
        crumb_names = []
    crumbs = [ {'name': name, 'path': '/' + '/'.join(crumb_names[:ind+1]) + '/'}
                    for ind, name in enumerate(crumb_names) ]
    # complete the crumbs home setting, and pop off if there is no home set.
    if CRUMBS_HOME:
        home = { 'name': CRUMBS_HOME, 'path': '/' }
        crumbs.insert(0, home)

    # strip off the root (if there is one)
    if rooturl.strip('/') and CRUMBS_STRIP_ROOT:
        crumbs = crumbs[len(rooturl.strip('/').split('/')):]
        if CRUMBS_HOME:
            crumbs[0]['name'] = CRUMBS_HOME
    
    navbars = get_navbar(request.user)
    for crumb in crumbs:
        for navbar in navbars:
            if crumb['path'] == navbar.url:
                crumb['name'] = navbar.name
                break

    return { 'crumbs': crumbs }
Example #3
0
def crumbs(request):
    """adds the path 'crumbs'
    crumbs have the format of:
    [ {'name': 'foo',  'path': '/foo'},
      {'name': 'bar',  'path': '/foo/bar'},
      {'name': 'bing', 'path': '/foo/bar/bing'} ]
    """
    rooturl = getattr(settings, 'ROOT_URL', '')
    assert (request.path.startswith(rooturl))
    if request.path != '/':
        # split the path into the names /name1/name2/name3
        crumb_names = request.path.strip('/').split('/')
    else:
        crumb_names = []
    crumbs = [{
        'name': name,
        'path': '/' + '/'.join(crumb_names[:ind + 1]) + '/'
    } for ind, name in enumerate(crumb_names)]
    # complete the crumbs home setting, and pop off if there is no home set.
    if CRUMBS_HOME:
        home = {'name': CRUMBS_HOME, 'path': '/'}
        crumbs.insert(0, home)

    # strip off the root (if there is one)
    if rooturl.strip('/') and CRUMBS_STRIP_ROOT:
        crumbs = crumbs[len(rooturl.strip('/').split('/')):]
        if CRUMBS_HOME:
            crumbs[0]['name'] = CRUMBS_HOME

    navbars = get_navbar(request.user)
    for crumb in crumbs:
        for navbar in navbars:
            if crumb['path'] == navbar.url:
                crumb['name'] = navbar.name
                break

    return {'crumbs': crumbs}
def navbar(request):
    """adds the variable 'navbar' to the context"
    """
    navbar = get_navbar(request.user)
    for ent in navbar: ent.selected = request.path.startswith(ent.url)
    return { 'navbar': navbar }