app/soc/views/sitemap/sidebar.py
changeset 1017 6ad4fdb48840
parent 1007 3b66772d21a5
child 1024 2a0ae6483825
equal deleted inserted replaced
1016:15a2f644725f 1017:6ad4fdb48840
    42   global SIDEBAR
    42   global SIDEBAR
    43   SIDEBAR.append(callback)
    43   SIDEBAR.append(callback)
    44 
    44 
    45 
    45 
    46 @soc.cache.sidebar.cache
    46 @soc.cache.sidebar.cache
    47 def getSidebar():
    47 def getSidebar(id, user):
    48   """Constructs a sidebar for the current user.
    48   """Constructs a sidebar for the current user.
    49   """
    49   """
    50 
    50 
    51   sidebar = []
    51   sidebar = []
    52 
    52 
    53   for callback in SIDEBAR:
    53   for callback in SIDEBAR:
    54     menus = callback()
    54     menus = callback(id, user)
    55 
    55 
    56     for menu in (menus if menus else []):
    56     for menu in (menus if menus else []):
    57       sidebar.append(menu)
    57       sidebar.append(menu)
    58 
    58 
    59   return sidebar
    59   return sidebar
   100     result.append(item)
   100     result.append(item)
   101 
   101 
   102   return result
   102   return result
   103 
   103 
   104 
   104 
   105 def getSidebarMenu(items, params):
   105 def getSidebarMenu(id, user, items, params):
   106   """Returns an dictionary with one sidebar entry.
   106   """Returns an dictionary with one sidebar entry.
   107 
   107 
   108   Items is expected to be a tuple with an url, a menu_text, and an
   108   Items is expected to be a tuple with an url, a menu_text, and an
   109   access_type. The access_type is then passed to checkAccess, if it
   109   access_type. The access_type is then passed to checkAccess, if it
   110   raises out_of_band.Error, the item will not be added.
   110   raises out_of_band.Error, the item will not be added.
   136   submenus = []
   136   submenus = []
   137 
   137 
   138   args = SIDEBAR_ACCESS_ARGS
   138   args = SIDEBAR_ACCESS_ARGS
   139   kwargs = SIDEBAR_ACCESS_KWARGS
   139   kwargs = SIDEBAR_ACCESS_KWARGS
   140 
   140 
       
   141   # reset and pre-fill the Checker's cache
       
   142   rights.setCurrentUser(id, user)
       
   143 
   141   for url, menu_text, access_type in items:
   144   for url, menu_text, access_type in items:
   142     try:
   145     try:
   143       rights.checkAccess(access_type, kwargs)
   146       rights.checkAccess(access_type, kwargs)
   144       submenus.append({'url': url, 'title': menu_text})
   147       submenus.append({'url': url, 'title': menu_text})
   145     except out_of_band.Error:
   148     except out_of_band.Error:
   146       pass
   149       pass
   147 
   150 
   148   return submenus
   151   return submenus
   149 
   152 
   150 
   153 
   151 def getSidebarMenus(params=None):
   154 def getSidebarMenus(id, user, params=None):
   152   """Constructs the default sidebar menu for a View.
   155   """Constructs the default sidebar menu for a View.
   153 
   156 
   154   Calls getSidebarItems to retrieve the items that should be in the
   157   Calls getSidebarItems to retrieve the items that should be in the
   155   menu. Then passes the result to getSidebarMenu. See the respective
   158   menu. Then passes the result to getSidebarMenu. See the respective
   156   docstrings for an explanation on what they do.
   159   docstrings for an explanation on what they do.
   158   Args:
   161   Args:
   159     params: a dict with params for this View
   162     params: a dict with params for this View
   160   """
   163   """
   161 
   164 
   162   items = getSidebarItems(params)
   165   items = getSidebarItems(params)
   163   submenus = getSidebarMenu(items, params)
   166   submenus = getSidebarMenu(id, user, items, params)
   164 
   167 
   165   if not submenus:
   168   if not submenus:
   166     return
   169     return
   167 
   170 
   168   menu = {}
   171   menu = {}