def format_sidebar(context): current_url_name = context['current_url_name'] active_tab = context.get('active_tab', None) request = context['request'] sections = active_tab.filtered_sidebar_items if active_tab else None if sections: # set is_active on active sidebar item by modifying nav by reference # and see if the nav needs a subnav for the current contextual item for section_title, navs in sections: for nav in navs: full_path = request.get_full_path() if path_starts_with_url(full_path, nav['url']): nav['is_active'] = True else: nav['is_active'] = False if 'subpages' in nav: for subpage in nav['subpages']: if subpage['urlname'] == current_url_name: if callable(subpage['title']): actual_context = {} for d in context.dicts: actual_context.update(d) subpage['is_active'] = True subpage['title'] = subpage['title']( **actual_context) nav['subpage'] = subpage break return render_to_string('hqwebapp/partials/navigation_left_sidebar.html', {'sections': sections})
def format_sidebar(context): current_url_name = context['current_url_name'] active_tab = context.get('active_tab', None) request = context['request'] sections = active_tab.filtered_sidebar_items if active_tab else None if sections: # set is_active on active sidebar item by modifying nav by reference # and see if the nav needs a subnav for the current contextual item for section_title, navs in sections: for nav in navs: full_path = request.get_full_path() if path_starts_with_url(full_path, nav['url']): nav['is_active'] = True else: nav['is_active'] = False if 'subpages' in nav: for subpage in nav['subpages']: if subpage['urlname'] == current_url_name: if callable(subpage['title']): actual_context = {} for d in context.dicts: actual_context.update(d) subpage['is_active'] = True subpage['title'] = subpage['title'](**actual_context) nav['subpage'] = subpage break return mark_safe(render_to_string( 'style/partials/navigation_left_sidebar.html', {'sections': sections} ))