Prepare for callbacks that return more than one menu
authorSverre Rabbelier <srabbelier@gmail.com>
Sun, 07 Dec 2008 13:49:22 +0000
changeset 697 190b65431579
parent 696 0d8515fb5314
child 698 a953f0676699
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
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