~ubuntu-branches/ubuntu/precise/horizon/precise-updates

« back to all changes in this revision

Viewing changes to horizon/middleware.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman, Adrien Cunin
  • Date: 2012-04-04 07:21:15 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120404072115-lb9v3gq3yv93ern2
Tags: 2012.1~rc2-0ubuntu1
[ Chuck Short ]
* New usptream release.
* debian/control: Use python-cherrypy3
* debian/rules: Update pythonpath in order to run tests.
* debian/patches/fix-coverage-binary-name.patch: Make the testsuite
  run.
* debian/rules: Fail build if tests fail.

[ Adam Gandelman ]
* debian/control: Add python-memcache 
* debain/dashboard.conf: Update to match current upstream documentation
  (LP: #966069)

[ Adrien Cunin ]
* Renamed Apache config file from dashboard.conf to openstack-dashboard.conf
  (LP: #965410)
  - Updated post{inst,rm} and added preinst to handle correctly the rename

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
        Catches internal Horizon exception classes such as NotAuthorized,
58
58
        NotFound and Http302 and handles them gracefully.
59
59
        """
60
 
        if isinstance(exception, exceptions.NotAuthorized):
 
60
        if isinstance(exception,
 
61
                (exceptions.NotAuthorized, exceptions.NotAuthenticated)):
61
62
            auth_url = reverse("horizon:auth_login")
62
63
            next_url = iri_to_uri(request.get_full_path())
63
64
            if next_url != auth_url:
68
69
            messages.error(request, unicode(exception))
69
70
            if request.is_ajax():
70
71
                response_401 = http.HttpResponse(status=401)
71
 
                response_401["REDIRECT_URL"] = redirect_to
 
72
                response_401['X-Horizon-Location'] = redirect_to
72
73
                return response_401
73
74
            return shortcuts.redirect(redirect_to)
74
75
 
80
81
            if exception.message:
81
82
                messages.error(request, exception.message)
82
83
            return shortcuts.redirect(exception.location)
 
84
 
 
85
    def process_response(self, request, response):
 
86
        """
 
87
        Convert HttpResponseRedirect to HttpResponse if request is via ajax
 
88
        to allow ajax request to redirect url
 
89
        """
 
90
        if request.is_ajax():
 
91
            if type(response) == http.HttpResponseRedirect:
 
92
                redirect_response = http.HttpResponse()
 
93
                redirect_response['X-Horizon-Location'] = response['location']
 
94
                return redirect_response
 
95
        return response