# HG changeset patch # User Sverre Rabbelier # Date 1228657762 0 # Node ID 190b654315791f39adf54efa0d4a00572c2bf994 # Parent 0d8515fb5314c699713eb4488c936ec39f13bc80 Prepare for callbacks that return more than one menu This paves the way for callbacks that dynamically construct their menu based on in-db content, such as Programs and Documents. Patch by: Sverre Rabbelier diff -r 0d8515fb5314 -r 190b65431579 app/soc/views/sitemap/sidebar.py --- a/app/soc/views/sitemap/sidebar.py Sun Dec 07 13:38:53 2008 +0000 +++ b/app/soc/views/sitemap/sidebar.py Sun Dec 07 13:49:22 2008 +0000 @@ -30,17 +30,24 @@ def addMenu(callback): + """Adds a callback to the menu builder. + + The callback should return a list of menu's when called. + """ + global SIDEBAR SIDEBAR.append(callback) def getSidebar(request): + """Constructs a sidebar for the specified request + """ + sidebar = [] for callback in SIDEBAR: - menu = callback(request) - - if menu: - # only if there is a menu we should append it + menus = callback(request) + + for menu in (menus if menus else []): sidebar.append(menu) return sidebar @@ -129,12 +136,14 @@ if not items: return - res = {} + menu = {} if 'sidebar_heading' not in params: params['sidebar_heading'] = params['name'] - res['heading'] = params['sidebar_heading'] - res['items'] = items + menu['heading'] = params['sidebar_heading'] + menu['items'] = items - return res + menus = [menu] + + return menus