예제 #1
0
def domains_for_user(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]
    context = {
        'is_public': selected_domain == 'public',
        'domain_list': domain_list,
        'current_domain': selected_domain,
    }
    template = {
        style_utils.BOOTSTRAP_2: 'hqwebapp/partials/domain_list_dropdown.html',
        style_utils.BOOTSTRAP_3: 'style/includes/domain_list_dropdown.html',
    }[style_utils.bootstrap_version(request)]
    return mark_safe(render_to_string(template, context))
예제 #2
0
def domains_for_user(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.
    """

    lst = list()
    lst.append('<ul class="dropdown-menu nav-list dropdown-orange">')
    new_domain_url = reverse("registration_domain")
    if selected_domain == 'public':
        # viewing the public domain with a different db, so the user's domains can't readily be accessed.
        lst.append('<li><a href="%s">%s...</a></li>' %
                   (reverse("domain_select"), _("Back to My Projects")))
        lst.append('<li class="divider"></li>')
    else:

        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)

        if len(domain_list) > 0:
            lst.append('<li class="nav-header">%s</li>' % _('My Projects'))
            for domain in domain_list:
                default_url = reverse("domain_homepage", args=[domain.name])
                lst.append('<li><a href="%s">%s</a></li>' %
                           (default_url, domain.long_display_name()))
        else:
            lst.append('<li class="nav-header">No Projects</li>')
    lst.append('<li class="divider"></li>')
    lst.append('<li><a href="%s">%s...</a></li>' %
               (new_domain_url, _('New Project')))
    lst.append('<li><a href="%s">%s...</a></li>' %
               (reverse("appstore"), _('CommCare Exchange')))
    lst.append("</ul>")

    domain_list_str = "".join(lst)
    return domain_list_str
예제 #3
0
def list_my_domains(request):
    cached_val = cache_core.get_cached_prop(request.couch_user.get_id, 'list_my_domains')
    if cached_val:
        return cached_val.get('list_my_domains', "")

    domain_list = Domain.active_for_user(request.user)
    lst = list()
    lst.append('<ul class="nav nav-pills nav-stacked">')
    for domain in domain_list:
        default_url = reverse("domain_homepage", args=[domain.name])
        lst.append('<li><a href="%s">%s</a></li>' % (default_url, domain.display_name()))
    lst.append('</ul>')

    my_domain_list_str = "".join(lst)
    ret = {"list_my_domains": my_domain_list_str}
    cache_core.cache_doc_prop(request.couch_user.get_id, 'list_my_domains', ret)
    return my_domain_list_str
예제 #4
0
def domains_for_user(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.
    """


    lst = list()
    lst.append('<ul class="dropdown-menu nav-list dropdown-orange">')
    new_domain_url = reverse("registration_domain")
    if selected_domain == 'public':
        # viewing the public domain with a different db, so the user's domains can't readily be accessed.
        lst.append('<li><a href="%s">%s...</a></li>' % (reverse("domain_select"), _("Back to My Projects")))
        lst.append('<li class="divider"></li>')
    else:

        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)

        if len(domain_list) > 0:
            lst.append('<li class="nav-header">%s</li>' % _('My Projects'))
            for domain in domain_list:
                default_url = reverse("domain_homepage", args=[domain.name])
                lst.append('<li><a href="%s">%s</a></li>' % (default_url, domain.long_display_name()))
        else:
            lst.append('<li class="nav-header">No Projects</li>')
    lst.append('<li class="divider"></li>')
    lst.append('<li><a href="%s">%s...</a></li>' % (new_domain_url, _('New Project')))
    lst.append('<li><a href="%s">%s...</a></li>' % (reverse("appstore"), _('CommCare Exchange')))
    lst.append("</ul>")

    domain_list_str = "".join(lst)
    return domain_list_str
예제 #5
0
def list_my_domains(request):
    cached_val = cache_core.get_cached_prop(request.couch_user.get_id,
                                            'list_my_domains')
    if cached_val:
        return cached_val.get('list_my_domains', "")

    domain_list = Domain.active_for_user(request.user)
    lst = list()
    lst.append('<ul class="nav nav-pills nav-stacked">')
    for domain in domain_list:
        default_url = reverse("domain_homepage", args=[domain.name])
        lst.append('<li><a href="%s">%s</a></li>' %
                   (default_url, domain.display_name()))
    lst.append('</ul>')

    my_domain_list_str = "".join(lst)
    ret = {"list_my_domains": my_domain_list_str}
    cache_core.cache_doc_prop(request.couch_user.get_id, 'list_my_domains',
                              ret)
    return my_domain_list_str