diff --git a/tailbone/menus.py b/tailbone/menus.py index b3bb09f1..ea7a86b3 100644 --- a/tailbone/menus.py +++ b/tailbone/menus.py @@ -38,7 +38,12 @@ class MenuGroup(Object): class MenuItem(Object): title = None url = None - perm = None + target = None + is_sep = False + + +class MenuSeparator(object): + is_sep = True def make_simple_menus(request): @@ -58,16 +63,43 @@ def make_simple_menus(request): for topitem in raw_menus: # figure out which ones the user has permission to access - allowed = [item for item in topitem['items'] - if request.has_perm(item['perm'])] + allowed = [] + for item in topitem['items']: + + if item.get('type') == 'sep': + allowed.append(item) + + if item.get('perm'): + if request.has_perm(item['perm']): + allowed.append(item) + else: + allowed.append(item) + if allowed: - # okay, user must have access to something; add the menu - items = [MenuItem(title=item['title'], - url=item['url'], - perm=item['perm']) - for item in allowed] - final_menus.append( - MenuGroup(title=topitem['title'], items=items)) + # user must have access to something; construct items for the menu + menu_items = [] + for item in allowed: + + # separator + if item.get('type') == 'sep': + if menu_items and not menu_items[-1].is_sep: + menu_items.append(MenuSeparator()) + + # menu item + else: + menu_items.append( + MenuItem(title=item['title'], + url=item['url'], + target=item.get('target'))) + + # remove final separator if present + if menu_items and menu_items[-1].is_sep: + menu_items.pop() + + # only add if we wound up with something + if menu_items: + final_menus.append( + MenuGroup(title=topitem['title'], items=menu_items)) return final_menus diff --git a/tailbone/templates/menu.mako b/tailbone/templates/menu.mako new file mode 100644 index 00000000..29fdd229 --- /dev/null +++ b/tailbone/templates/menu.mako @@ -0,0 +1,39 @@ +## -*- coding: utf-8; -*- + +<%def name="main_menu_items()"> + + % for topitem in menus: +