Add more information on deploying; fix format.
[ganeti_webmgr.git] / ganeti_web / middleware.py
blobc6ce8f2b592fce0d20bccf6405cf465e37fd997e
1 # Copyright (c) 2012 Oregon State University
2 # See license and copying files for copyright information.
4 # This module provides middleware which Django is too wimpy to provide itself.
6 from django.http import HttpResponseForbidden
7 from django.template import RequestContext, loader
10 class Http403(Exception):
11 """
12 A 403 error should be sent back to our client.
13 """
16 def render_403(request, message):
17 """
18 Render a 403 response.
19 """
21 template = loader.get_template('403.html')
22 context = RequestContext(request, {
23 'message': message,
26 return HttpResponseForbidden(template.render(context))
29 class Http403Middleware(object):
30 """
31 Middleware which intercepts ``Http403`` exceptions and returns 403
32 responses.
33 """
35 def process_exception(self, request, e):
36 if isinstance(e, Http403):
37 return render_403(request, ", ".join(e.args))