def _process_response(self, request, response):
        """Convert HttpResponseRedirect to HttpResponse if request is via ajax.

        This is to allow ajax request to redirect url.
        """
        if request.is_ajax() and hasattr(request, 'horizon'):
            queued_msgs = request.horizon['async_messages']
            if type(response) == http.HttpResponseRedirect:
                # Drop our messages back into the session as per usual so they
                # don't disappear during the redirect. Not that we explicitly
                # use django's messages methods here.
                for tag, message, extra_tags in queued_msgs:
                    getattr(django_messages, tag)(request, message, extra_tags)
                if response['location'].startswith(settings.LOGOUT_URL):
                    redirect_response = http.HttpResponse(status=401)
                    # This header is used for handling the logout in JS
                    redirect_response['logout'] = True
                    if self.logout_reason is not None:
                        utils.add_logout_reason(
                            request, redirect_response, self.logout_reason,
                            'error')
                else:
                    redirect_response = http.HttpResponse()
                # Use a set while checking if we want a cookie's attributes
                # copied
                cookie_keys = {'max_age', 'expires', 'path', 'domain',
                               'secure', 'httponly', 'logout_reason'}
                # Copy cookies from HttpResponseRedirect towards HttpResponse
                for cookie_name, cookie in response.cookies.items():
                    cookie_kwargs = dict((
                        (key, value) for key, value in cookie.items()
                        if key in cookie_keys and value
                    ))
                    redirect_response.set_cookie(
                        cookie_name, cookie.value, **cookie_kwargs)
                redirect_response['X-Horizon-Location'] = response['location']
                upload_url_key = 'X-File-Upload-URL'
                if upload_url_key in response:
                    self._copy_headers(response, redirect_response,
                                       (upload_url_key, 'X-Auth-Token'))
                return redirect_response
            if queued_msgs:
                # TODO(gabriel): When we have an async connection to the
                # client (e.g. websockets) this should be pushed to the
                # socket queue rather than being sent via a header.
                # The header method has notable drawbacks (length limits,
                # etc.) and is not meant as a long-term solution.
                response['X-Horizon-Messages'] = json.dumps(queued_msgs)
        return response
def _process_response ( self , request , response ) : if request . is_ajax ( ) and hasattr ( request , 'horizon' ) : queued_msgs = request . horizon [ 'async_messages' ] if type ( response ) == http . HttpResponseRedirect : for tag , message , extra_tags in queued_msgs : getattr ( django_messages , tag ) ( request , message , extra_tags ) if response [ 'location' ] . startswith ( settings . LOGOUT_URL ) : redirect_response = http . HttpResponse ( status = 401 ) redirect_response [ 'logout' ] = True if self . logout_reason is not None : utils . add_logout_reason ( request , redirect_response , self . logout_reason , 'error' ) else : redirect_response = http . HttpResponse ( ) cookie_keys = { 'max_age' , 'expires' , 'path' , 'domain' , 'secure' , 'httponly' , 'logout_reason' } for cookie_name , cookie in response . cookies . items ( ) : cookie_kwargs = dict ( ( ( key , value ) for key , value in cookie . items ( ) if key in cookie_keys and value ) ) redirect_response . set_cookie ( cookie_name , cookie . value , ** cookie_kwargs ) redirect_response [ 'X-Horizon-Location' ] = response [ 'location' ] upload_url_key = 'X-File-Upload-URL' if upload_url_key in response : self . _copy_headers ( response , redirect_response , ( upload_url_key , 'X-Auth-Token' ) ) return redirect_response if queued_msgs : response [ 'X-Horizon-Messages' ] = json . dumps ( queued_msgs ) return response
Convert HttpResponseRedirect to HttpResponse if request is via ajax.

        This is to allow ajax request to redirect url.