diff --git a/tailbone/menus.py b/tailbone/menus.py index ea7a86b3..f28574bf 100644 --- a/tailbone/menus.py +++ b/tailbone/menus.py @@ -33,12 +33,14 @@ from rattail.util import import_module_path class MenuGroup(Object): title = None items = None + is_link = False class MenuItem(Object): title = None url = None target = None + is_link = True is_sep = False @@ -62,44 +64,52 @@ def make_simple_menus(request): final_menus = [] for topitem in raw_menus: - # figure out which ones the user has permission to access - allowed = [] - for item in topitem['items']: + if topitem.get('type') == 'link': + final_menus.append( + MenuItem(title=topitem['title'], + url=topitem['url'], + target=topitem.get('target'))) - if item.get('type') == 'sep': - allowed.append(item) + else: # assuming 'menu' type - if item.get('perm'): - if request.has_perm(item['perm']): - allowed.append(item) - else: - allowed.append(item) + # figure out which ones the user has permission to access + allowed = [] + for item in topitem['items']: - if allowed: - - # 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()) + allowed.append(item) - # menu item + if item.get('perm'): + if request.has_perm(item['perm']): + allowed.append(item) else: - menu_items.append( - MenuItem(title=item['title'], - url=item['url'], - target=item.get('target'))) + allowed.append(item) - # remove final separator if present - if menu_items and menu_items[-1].is_sep: - menu_items.pop() + if allowed: - # only add if we wound up with something - if menu_items: - final_menus.append( - MenuGroup(title=topitem['title'], items=menu_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/subscribers.py b/tailbone/subscribers.py index 6af90cbc..1a610ef2 100644 --- a/tailbone/subscribers.py +++ b/tailbone/subscribers.py @@ -120,6 +120,10 @@ def before_render(event): if request.rattail_config.getbool('tailbone', 'menus.simple', default=False): renderer_globals['menus'] = make_simple_menus(request) + # TODO: ugh, same deal here + renderer_globals['messaging_enabled'] = request.rattail_config.getbool( + 'tailbone', 'messaging.enabled', default=True) + def add_inbox_count(event): """ diff --git a/tailbone/templates/menu.mako b/tailbone/templates/menu.mako index 29fdd229..7549e763 100644 --- a/tailbone/templates/menu.mako +++ b/tailbone/templates/menu.mako @@ -4,30 +4,40 @@ % for topitem in menus: