def domains_for_user(context, request, selected_domain=None): """ Generate pulldown menu for domains. Cache the entire string alongside the couch_user's doc_id that can get invalidated when the user doc updates via save. """ domain_list = [] if selected_domain != 'public': domain_list = Domain.active_for_user(request.couch_user) domain_list = [ dict(url=reverse('domain_homepage', args=[d.name]), name=d.long_display_name()) for d in domain_list ] ctxt = { 'is_public': selected_domain == 'public', 'domain_list': domain_list, 'current_domain': selected_domain, 'DOMAIN_TYPE': context['DOMAIN_TYPE'] } template = { style_utils.BOOTSTRAP_2: 'style/bootstrap2/partials/domain_list_dropdown.html', style_utils.BOOTSTRAP_3: 'style/bootstrap3/partials/domain_list_dropdown.html', }[style_utils.get_bootstrap_version()] return mark_safe(render_to_string(template, ctxt))
def format_sidebar(context): current_url_name = context['current_url_name'] active_tab = context.get('active_tab', None) request = context['request'] sections = None if active_tab and active_tab.subtabs: # if active_tab is active then at least one of its subtabs should have # is_active == True, but we guard against the possibility of this not # being the case by setting sections = None above for s in active_tab.subtabs: if s.is_active: sections = s.sidebar_items break if sections is None: for s in active_tab.subtabs: if s.url and request.get_full_path().startswith(s.url): sections = s.sidebar_items break else: sections = active_tab.sidebar_items if active_tab else None def _strip_scheme(uri): return uri.lstrip('https') 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() # The path of the URL after the domain absolute_uri = request.build_absolute_uri() # The full uri {scheme}{host}{path} if (full_path.startswith(nav['url']) or _strip_scheme(absolute_uri).startswith(_strip_scheme(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 template = { style_utils.BOOTSTRAP_2: 'style/bootstrap2/partials/navigation_left_sidebar.html', style_utils.BOOTSTRAP_3: 'style/bootstrap3/partials/navigation_left_sidebar.html', }[style_utils.get_bootstrap_version()] return mark_safe(render_to_string(template, { 'sections': sections }))
def format_sidebar(context): current_url_name = context['current_url_name'] active_tab = context.get('active_tab', None) request = context['request'] sections = None if active_tab and active_tab.subtabs: # if active_tab is active then at least one of its subtabs should have # is_active == True, but we guard against the possibility of this not # being the case by setting sections = None above for s in active_tab.subtabs: if s.is_active: sections = s.sidebar_items break if sections is None: for s in active_tab.subtabs: if s.url and request.get_full_path().startswith(s.url): sections = s.sidebar_items break else: sections = active_tab.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: if (request.get_full_path().startswith(nav['url']) or request.build_absolute_uri().startswith(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['title'] = subpage['title']( **actual_context) nav['subpage'] = subpage break template = { style_utils.BOOTSTRAP_2: 'style/bootstrap2/partials/navigation_left_sidebar.html', style_utils.BOOTSTRAP_3: 'style/bootstrap3/partials/navigation_left_sidebar.html', }[style_utils.get_bootstrap_version()] return mark_safe(render_to_string(template, {'sections': sections}))
def domains_for_user(context, request, selected_domain=None): """ Generate pulldown menu for domains. Cache the entire string alongside the couch_user's doc_id that can get invalidated when the user doc updates via save. """ domain_list = _get_domain_list(request.couch_user) ctxt = { 'domain_list': domain_list, 'current_domain': selected_domain, 'DOMAIN_TYPE': context['DOMAIN_TYPE'] } template = { style_utils.BOOTSTRAP_2: 'style/bootstrap2/partials/domain_list_dropdown.html', style_utils.BOOTSTRAP_3: 'style/bootstrap3/partials/domain_list_dropdown.html', }[style_utils.get_bootstrap_version()] return mark_safe(render_to_string(template, ctxt))
def render(self, context): request = context['request'] current_url_name = context['current_url_name'] couch_user = getattr(request, 'couch_user', None) project = getattr(request, 'project', None) domain = context.get('domain') org = context.get('org') try: module = Domain.get_module_by_name(domain) except (ValueError, AttributeError): module = None tabs = getattr(module, 'TABS', corehq.TABS) visible_tabs = [] for tab_class in tabs: t = tab_class(request, current_url_name, domain=domain, couch_user=couch_user, project=project, org=org) t.is_active_tab = False if t.real_is_viewable: visible_tabs.append(t) # set the context variable in the highest scope so it can be used in # other blocks context.dicts[0]['active_tab'] = get_active_tab( visible_tabs, request.get_full_path()) template = { style_utils.BOOTSTRAP_2: 'style/bootstrap2/partials/menu_main.html', style_utils.BOOTSTRAP_3: 'style/bootstrap3/partials/menu_main.html', }[style_utils.get_bootstrap_version()] return mark_safe(render_to_string(template, { 'tabs': visible_tabs, }))
def render(self, context): request = context['request'] current_url_name = context['current_url_name'] couch_user = getattr(request, 'couch_user', None) project = getattr(request, 'project', None) domain = context.get('domain') org = context.get('org') try: module = Domain.get_module_by_name(domain) except (ValueError, AttributeError): module = None tabs = getattr(module, 'TABS', corehq.TABS) visible_tabs = [] for tab_class in tabs: t = tab_class( request, current_url_name, domain=domain, couch_user=couch_user, project=project, org=org) t.is_active_tab = False if t.real_is_viewable: visible_tabs.append(t) # set the context variable in the highest scope so it can be used in # other blocks context.dicts[0]['active_tab'] = get_active_tab(visible_tabs, request.get_full_path()) template = { style_utils.BOOTSTRAP_2: 'style/bootstrap2/partials/menu_main.html', style_utils.BOOTSTRAP_3: 'style/bootstrap3/partials/menu_main.html', }[style_utils.get_bootstrap_version()] return mark_safe(render_to_string(template, { 'tabs': visible_tabs, }))
def domains_for_user(context, request, selected_domain=None): """ Generate pulldown menu for domains. Cache the entire string alongside the couch_user's doc_id that can get invalidated when the user doc updates via save. """ domain_list = [] if selected_domain != 'public': cached_domains = cache_core.get_cached_prop(request.couch_user.get_id, 'domain_list') if cached_domains: domain_list = [Domain.wrap(x) for x in cached_domains] else: try: domain_list = Domain.active_for_user(request.couch_user) cache_core.cache_doc_prop(request.couch_user.get_id, 'domain_list', [x.to_json() for x in domain_list]) except Exception: if settings.DEBUG: raise else: domain_list = Domain.active_for_user(request.user) notify_exception(request) domain_list = [dict( url=reverse('domain_homepage', args=[d.name]), name=d.long_display_name() ) for d in domain_list] ctxt = { 'is_public': selected_domain == 'public', 'domain_list': domain_list, 'current_domain': selected_domain, 'DOMAIN_TYPE': context['DOMAIN_TYPE'] } template = { style_utils.BOOTSTRAP_2: 'style/bootstrap2/partials/domain_list_dropdown.html', style_utils.BOOTSTRAP_3: 'style/bootstrap3/partials/domain_list_dropdown.html', }[style_utils.get_bootstrap_version()] return mark_safe(render_to_string(template, ctxt))
def domains_for_user(context, request, selected_domain=None): """ Generate pulldown menu for domains. Cache the entire string alongside the couch_user's doc_id that can get invalidated when the user doc updates via save. """ domain_list = [] if selected_domain != 'public': domain_list = Domain.active_for_user(request.couch_user) domain_list = [dict( url=reverse('domain_homepage', args=[d.name]), name=d.long_display_name() ) for d in domain_list] ctxt = { 'is_public': selected_domain == 'public', 'domain_list': domain_list, 'current_domain': selected_domain, 'DOMAIN_TYPE': context['DOMAIN_TYPE'] } template = { style_utils.BOOTSTRAP_2: 'style/bootstrap2/partials/domain_list_dropdown.html', style_utils.BOOTSTRAP_3: 'style/bootstrap3/partials/domain_list_dropdown.html', }[style_utils.get_bootstrap_version()] return mark_safe(render_to_string(template, ctxt))
def render(self, context): request = context['request'] current_url_name = context['current_url_name'] couch_user = getattr(request, 'couch_user', None) project = getattr(request, 'project', None) domain = context.get('domain') org = context.get('org') try: module = Domain.get_module_by_name(domain) except (ValueError, AttributeError): module = None tabs = getattr(module, 'TABS', corehq.TABS) visible_tabs = [] all_tabs = [] active_tab = None for tab_class in tabs: t = tab_class( request, current_url_name, domain=domain, couch_user=couch_user, project=project, org=org) t.is_active_tab = False all_tabs.append(t) if t.real_is_viewable: visible_tabs.append(t) # only highlight the first tab considered active. This allows # multiple tabs to contain the same sidebar item, but in all but # the first it will effectively be a link to the other tabs. for t in all_tabs: if t.is_active_fast: t.is_active_tab = True active_tab = t break if active_tab is None: for t in all_tabs: if t.is_active: t.is_active_tab = True active_tab = t break if active_tab is None: for t in visible_tabs: if t.url and request.get_full_path().startswith(t.url): active_tab = t break # set the context variable in the highest scope so it can be used in # other blocks context.dicts[0]['active_tab'] = active_tab template = { style_utils.BOOTSTRAP_2: 'style/bootstrap2/partials/menu_main.html', style_utils.BOOTSTRAP_3: 'style/bootstrap3/partials/menu_main.html', }[style_utils.get_bootstrap_version()] return mark_safe(render_to_string(template, { 'tabs': visible_tabs, }))