app/soc/views/sitemap/sidebar.py
changeset 704 8647e6b441fc
parent 703 c4f3997becd9
child 714 3e2ce3d8057a
equal deleted inserted replaced
703:c4f3997becd9 704:8647e6b441fc
    79   # Construct defaults manualy
    79   # Construct defaults manualy
    80   defaults = params['sidebar_defaults']
    80   defaults = params['sidebar_defaults']
    81 
    81 
    82   result = []
    82   result = []
    83 
    83 
       
    84   for item in params['sidebar_additional']:
       
    85     result.append(item)
       
    86 
    84   for url, menu_text, access_type in defaults:
    87   for url, menu_text, access_type in defaults:
    85     url = url % params['url_name'].lower()
    88     url = url % params['url_name'].lower()
    86     item = (url, menu_text % params, access_type)
    89     item = (url, menu_text % params, access_type)
    87     result.append(item)
    90     result.append(item)
    88 
    91 
    89   for item in params['sidebar_additional']:
       
    90     result.append(item)
       
    91 
       
    92   return result
    92   return result
    93 
    93 
    94 
    94 
    95 def getSidebarMenus(request, params=None):
    95 def getSidebarMenu(request, items, params):
    96   """Returns an dictionary with one sidebar entry.
    96   """Returns an dictionary with one sidebar entry.
    97 
    97 
    98   Calls getSidebarItems to retrieve the items that should be in the
    98   Items is expected to be a tuple with an url, a menu_text, and an
    99   menu. Expected is a tuple with an url, a menu_text, and an
       
   100   access_type. The access_type is then passed to checkAccess, if it
    99   access_type. The access_type is then passed to checkAccess, if it
   101   raises out_of_band.Error, the item will not be added.
   100   raises out_of_band.Error, the item will not be added.
   102 
   101 
   103   Args:
   102   Args:
       
   103     items: see above
   104     request: the django request object
   104     request: the django request object
   105     params: a dict with params for this View
   105     params: a dict with params for this View
   106 
   106 
   107   Params usage:
   107   Params usage:
   108     The params dictionary is passed as argument to getSidebarItems,
   108     The params dictionary is passed as argument to getSidebarItems,
   122     of dictionaries with a url and a title field.
   122     of dictionaries with a url and a title field.
   123   """
   123   """
   124 
   124 
   125   rights = params['rights']
   125   rights = params['rights']
   126 
   126 
   127   items = []
   127   submenus = []
   128 
   128 
   129   for url, menu_text, access_type in getSidebarItems(params):
   129   for url, menu_text, access_type in items:
   130     try:
   130     try:
   131       access.checkAccess(access_type, request, rights)
   131       access.checkAccess(access_type, request, rights)
   132       items.append({'url': url, 'title': menu_text})
   132       submenus.append({'url': url, 'title': menu_text})
   133     except out_of_band.Error:
   133     except out_of_band.Error:
   134       pass
   134       pass
   135 
   135 
   136   if not items:
   136   return submenus
       
   137 
       
   138 
       
   139 def getSidebarMenus(request, params=None):
       
   140   """Constructs the default sidebar menu for a View.
       
   141 
       
   142   Calls getSidebarItems to retrieve the items that should be in the
       
   143   menu. Then passes the result to getSidebarMenu. See the respective
       
   144   docstrings for an explanation on what they do.
       
   145 
       
   146   Args:
       
   147     request: the django request object
       
   148     params: a dict with params for this View
       
   149   """
       
   150 
       
   151   items = getSidebarItems(params)
       
   152   submenus = getSidebarMenu(request, items, params)
       
   153 
       
   154   if not submenus:
   137     return
   155     return
   138 
   156 
   139   menu = {}
   157   menu = {}
   140 
   158 
   141   if 'sidebar_heading' not in params:
   159   if 'sidebar_heading' not in params:
   142     params['sidebar_heading'] = params['name']
   160     params['sidebar_heading'] = params['name']
   143 
   161 
   144   menu['heading'] = params['sidebar_heading']
   162   menu['heading'] = params['sidebar_heading']
   145   menu['items'] = items
   163   menu['items'] = submenus
   146 
   164 
   147   menus = [menu]
   165   menus = [menu]
   148 
   166 
   149   return menus
   167   return menus