@datespan_default
    def dispatch(self, request, domain=None, report_slug=None, render_as=None,
                 permissions_check=None, *args, **kwargs):
        render_as = render_as or 'view'
        domain = domain or getattr(request, 'domain', None)

        redirect_slug = self._redirect_slug(report_slug)

        if redirect_slug and render_as == 'email':
            # todo saved reports should probably change the slug to the redirected slug. this seems like a hack.
            raise Http404
        elif redirect_slug:
            new_args = [domain] if domain else []
            if render_as != 'view':
                new_args.append(render_as)
            new_args.append(redirect_slug)
            return HttpResponseRedirect(reverse(self.name(), args=new_args))

        report_kwargs = kwargs.copy()

        cls = self.get_report(domain, report_slug)
        class_name = cls.__module__ + '.' + cls.__name__ if cls else ''

        permissions_check = permissions_check or self.permissions_check
        if (
            cls
            and permissions_check(class_name, request, domain=domain)
            and self.toggles_enabled(cls, request)
        ):
            report = cls(request, domain=domain, **report_kwargs)
            report.rendered_as = render_as
            try:
                if report.is_bootstrap3:
                    report.bootstrap3_dispatcher(
                        request, domain=domain, report_slug=report_slug, *args, **kwargs
                    )
                return getattr(report, '%s_response' % render_as)
            except BadRequestError, e:
                return HttpResponseBadRequest(e)
        else:
            raise Http404()
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/reports/dispatcher.py/ReportDispatcher.dispatch/original