app/soc/views/sitemap/sidebar.py
changeset 973 f9c2b32b9e2b
parent 972 43018f61b481
child 987 6fd5c561b446
equal deleted inserted replaced
972:43018f61b481 973:f9c2b32b9e2b
    38   """
    38   """
    39 
    39 
    40   global SIDEBAR
    40   global SIDEBAR
    41   SIDEBAR.append(callback)
    41   SIDEBAR.append(callback)
    42 
    42 
    43 def getSidebar(request):
    43 def getSidebar():
    44   """Constructs a sidebar for the specified request.
    44   """Constructs a sidebar for the current user.
    45   """
    45   """
    46 
    46 
    47   sidebar = []
    47   sidebar = []
    48 
    48 
    49   for callback in SIDEBAR:
    49   for callback in SIDEBAR:
    50     menus = callback(request)
    50     menus = callback()
    51 
    51 
    52     for menu in (menus if menus else []):
    52     for menu in (menus if menus else []):
    53       sidebar.append(menu)
    53       sidebar.append(menu)
    54 
    54 
    55   return sidebar
    55   return sidebar
    96     result.append(item)
    96     result.append(item)
    97 
    97 
    98   return result
    98   return result
    99 
    99 
   100 
   100 
   101 def getSidebarMenu(request, items, params):
   101 def getSidebarMenu(items, params):
   102   """Returns an dictionary with one sidebar entry.
   102   """Returns an dictionary with one sidebar entry.
   103 
   103 
   104   Items is expected to be a tuple with an url, a menu_text, and an
   104   Items is expected to be a tuple with an url, a menu_text, and an
   105   access_type. The access_type is then passed to checkAccess, if it
   105   access_type. The access_type is then passed to checkAccess, if it
   106   raises out_of_band.Error, the item will not be added.
   106   raises out_of_band.Error, the item will not be added.
   107 
   107 
   108   Args:
   108   Args:
   109     request: the django request object
       
   110     items: see above
   109     items: see above
   111     params: a dict with params for this View
   110     params: a dict with params for this View
   112 
   111 
   113   Params usage:
   112   Params usage:
   114     The params dictionary is passed as argument to getSidebarItems,
   113     The params dictionary is passed as argument to getSidebarItems,
   143       pass
   142       pass
   144 
   143 
   145   return submenus
   144   return submenus
   146 
   145 
   147 
   146 
   148 def getSidebarMenus(request, params=None):
   147 def getSidebarMenus(params=None):
   149   """Constructs the default sidebar menu for a View.
   148   """Constructs the default sidebar menu for a View.
   150 
   149 
   151   Calls getSidebarItems to retrieve the items that should be in the
   150   Calls getSidebarItems to retrieve the items that should be in the
   152   menu. Then passes the result to getSidebarMenu. See the respective
   151   menu. Then passes the result to getSidebarMenu. See the respective
   153   docstrings for an explanation on what they do.
   152   docstrings for an explanation on what they do.
   154 
   153 
   155   Args:
   154   Args:
   156     request: the django request object
       
   157     params: a dict with params for this View
   155     params: a dict with params for this View
   158   """
   156   """
   159 
   157 
   160   items = getSidebarItems(params)
   158   items = getSidebarItems(params)
   161   submenus = getSidebarMenu(request, items, params)
   159   submenus = getSidebarMenu(items, params)
   162 
   160 
   163   if not submenus:
   161   if not submenus:
   164     return
   162     return
   165 
   163 
   166   menu = {}
   164   menu = {}