示例#1
0
def main_menu_items():
    """Returns the main menu."""

    def assign_defaults(name,title,url,group=[]):
        return (name,title,url,group)

    links = []
    visible_items = []
    static_links = [assign_defaults(*item) for item in tools.get_menu()]

    for (name,title,url,group) in static_links:
        if group==[] or [item for item in group if item in user.groups]:
            if manager.get_app(name) and not manager.get_app(name).visible: continue
            selector = (len(route)>1 and route[0]=='content' and route[1]==name or len(route) and route[0]==name) and ' id="current"' or ''
            bootstrap_selector = (len(route)>1 and route[0]=='content' and route[1]==name or len(route) and route[0]==name) and ' class="active"' or ''
            links.append('<li%s><a href="%s"%s>%s</a></li>' % (bootstrap_selector,url_for(url), selector, title))
            visible_items.append(name)

    visible_items.extend(['content','login'])

    if user.is_developer:
        current_app = route[0]
        if not current_app in visible_items:
            if visible_items[0] in ['index','home']:
                pos = 1
            else:
                pos = 0
            url = '<li class="active"><a href="%s" id="current">%s</a></li>' % (url_for('/'+current_app),system.app.title)
            links.insert(pos, url)

    return ''.join(links)
示例#2
0
def main_menu_items():
    """Returns the main menu."""

    def assign_defaults(name,title,url,group=[]):
        return (name,title,url,group)

    links = []
    visible_items = []
    static_links = [assign_defaults(*item) for item in tools.get_menu()]

    for (name,title,url,group) in static_links:
        if group==[] or [item for item in group if item in user.groups]:
            selector = (len(route)>1 and route[0]=='content' and route[1]==name or len(route) and route[0]==name) and 'id="current"' or ''
            links.append('<a href="%s" %s>%s</a>' % (url_for(url), selector, title))
            visible_items.append(name)

    visible_items.extend(['content','login'])

    if user.is_developer:
        current_app = route[0]
        if not current_app in visible_items:
            if visible_items[0] in ['index','home']:
                pos = 1
            else:
                pos = 0
            url = '<a href="%s" id="current">%s</a>' % (url_for('/'+current_app),system.app.title)
            links.insert(pos, url)

    return html.li(links)
示例#3
0
def load_menu(name=None):
    """renders a menu"""
    if name:
        try:
            items = tools.get_menu(name)
            if not items:
                raise Exception('menu %s empty' % name)
        except:
            error('unable to read menu <b>"%s"</b>' % name)
            items = []
        links = []
        for item in items:
            title = item[0]
            url = item[1]
            groups = item[2]
            if groups==[] or [g for g in groups if g in user.groups]:
                links.append('<a href="%s">%s</a>' % (url_for(url), title))
        return html.ul(links)
示例#4
0
def load_menu(name=None):
    """renders a menu"""
    if name:
        try:
            items = tools.get_menu(name)
            if not items:
                raise Exception("menu %s empty" % name)
        except:
            error('unable to read menu <b>"%s"</b>' % name)
            items = []
        links = []
        for item in items:
            title = item[0]
            url = item[1]
            groups = item[2]
            if groups == [] or [g for g in groups if g in user.groups]:
                links.append('<a href="%s">%s</a>' % (url_for(url), title))
        return html.ul(links)
示例#5
0
def main_menu_items():
    """Returns the main menu."""

    def assign_defaults(name, title, url, group=[]):
        return (name, title, url, group)

    links = []
    visible_items = []
    static_links = [assign_defaults(*item) for item in tools.get_menu()]

    for (name, title, url, group) in static_links:
        if group == [] or [item for item in group if item in user.groups]:
            if manager.get_app(name) and not manager.get_app(name).visible:
                continue
            selector = (
                (len(route) > 1 and route[0] == "content" and route[1] == name or len(route) and route[0] == name)
                and ' id="current"'
                or ""
            )
            bootstrap_selector = (
                (len(route) > 1 and route[0] == "content" and route[1] == name or len(route) and route[0] == name)
                and ' class="active"'
                or ""
            )
            links.append('<li%s><a href="%s"%s>%s</a></li>' % (bootstrap_selector, url_for(url), selector, title))
            visible_items.append(name)

    visible_items.extend(["content", "login"])

    if user.is_developer:
        current_app = route[0]
        if not current_app in visible_items:
            if visible_items[0] in ["index", "home"]:
                pos = 1
            else:
                pos = 0
            url = '<li class="active"><a href="%s" id="current">%s</a></li>' % (
                url_for("/" + current_app),
                system.app.title,
            )
            links.insert(pos, url)

    return "".join(links)