示例#1
0
def redirect_to_default(req, domain=None):
    if not req.user.is_authenticated():
        if domain != None:
            url = reverse('domain_login', args=[domain])
        else:
            # this actually gets hijacked by the static site, but is necessary
            url = reverse('corehq.apps.hqwebapp.views.landing_page')
    else:
        if domain:
            domain = normalize_domain_name(domain)
            domains = [Domain.get_by_name(domain)]
        else:
            domains = Domain.active_for_user(req.user)
        if 0 == len(domains) and not req.user.is_superuser:
            return redirect('registration_domain')
        elif 1 == len(domains):
            if domains[0]:
                domain = domains[0].name
                if req.couch_user.is_commcare_user():
                    if not is_mobile_worker_with_report_access(
                            req.couch_user, domain):
                        url = reverse("cloudcare_main", args=[domain, ""])
                    else:
                        url = reverse("saved_reports", args=[domain])
                elif req.couch_user.can_view_reports(domain) or req.couch_user.get_viewable_reports(domain):
                    url = reverse('corehq.apps.reports.views.default', args=[domain])
                else:
                    url = reverse('corehq.apps.app_manager.views.default', args=[domain])
            else:
                raise Http404
        else:
            url = settings.DOMAIN_SELECT_URL
    return HttpResponseRedirect(url)
示例#2
0
def redirect_to_default(req, domain=None):
    if not req.user.is_authenticated():
        if domain != None:
            url = reverse('domain_login', args=[domain])
        else:
            try:
                from corehq.apps.prelogin.views import HomePublicView
                url = reverse(HomePublicView.urlname)
            except ImportError:
                # this happens when the prelogin app is not included.
                url = reverse('landing_page')
    else:
        if domain:
            domain = normalize_domain_name(domain)
            domains = [Domain.get_by_name(domain)]
        else:
            domains = Domain.active_for_user(req.user)
        if 0 == len(domains) and not req.user.is_superuser:
            return redirect('registration_domain', domain_type=get_domain_type(None, req))
        elif 1 == len(domains):
            if domains[0]:
                domain = domains[0].name

                if (req.couch_user.is_commcare_user()
                    and not is_mobile_worker_with_report_access(
                        req.couch_user, domain)):
                    url = reverse("cloudcare_main", args=[domain, ""])
                else:
                    url = reverse('dashboard_default', args=[domain])

            else:
                raise Http404
        else:
            url = settings.DOMAIN_SELECT_URL
    return HttpResponseRedirect(url)
示例#3
0
def redirect_to_default(req, domain=None):
    if not req.user.is_authenticated():
        if domain != None:
            url = reverse('domain_login', args=[domain])
        else:
            # this actually gets hijacked by the static site, but is necessary
            url = reverse('corehq.apps.hqwebapp.views.landing_page')
    else:
        if domain:
            domain = normalize_domain_name(domain)
            domains = [Domain.get_by_name(domain)]
        else:
            domains = Domain.active_for_user(req.user)
        if 0 == len(domains) and not req.user.is_superuser:
            return redirect('registration_domain')
        elif 1 == len(domains):
            if domains[0]:
                domain = domains[0].name

                if toggles.DASHBOARD_PREVIEW.enabled(req.couch_user.username):
                    url = reverse('dashboard_default', args=[domain])
                    if (req.couch_user.is_commcare_user()
                            and not is_mobile_worker_with_report_access(
                                req.couch_user, domain)):
                        url = reverse("cloudcare_main", args=[domain, ""])

                elif req.couch_user.is_commcare_user():
                    if not is_mobile_worker_with_report_access(
                            req.couch_user, domain):
                        url = reverse("cloudcare_main", args=[domain, ""])
                    else:
                        url = reverse("saved_reports", args=[domain])
                elif req.couch_user.can_view_reports(
                        domain) or req.couch_user.get_viewable_reports(domain):
                    url = reverse('corehq.apps.reports.views.default',
                                  args=[domain])
                else:
                    url = reverse('corehq.apps.app_manager.views.default',
                                  args=[domain])
            else:
                raise Http404
        else:
            url = settings.DOMAIN_SELECT_URL
    return HttpResponseRedirect(url)
示例#4
0
def redirect_to_default(req, domain=None):
    if not req.user.is_authenticated():
        if domain != None:
            url = reverse('domain_login', args=[domain])
        else:
            try:
                from corehq.apps.prelogin.views import HomePublicView
                url = reverse(HomePublicView.urlname)
            except ImportError:
                # this happens when the prelogin app is not included.
                url = reverse('landing_page')
    else:
        if domain:
            domain = normalize_domain_name(domain)
            domains = [Domain.get_by_name(domain)]
        else:
            domains = Domain.active_for_user(req.user)
        if 0 == len(domains) and not req.user.is_superuser:
            return redirect('registration_domain',
                            domain_type=get_domain_type(None, req))
        elif 1 == len(domains):
            if domains[0]:
                domain = domains[0].name

                if (req.couch_user.is_commcare_user()
                        and not is_mobile_worker_with_report_access(
                            req.couch_user, domain)):
                    url = reverse("cloudcare_main", args=[domain, ""])
                else:
                    url = reverse('dashboard_default', args=[domain])

            else:
                raise Http404
        else:
            url = settings.DOMAIN_SELECT_URL
    return HttpResponseRedirect(url)