diff -r 478c7fc9a223 -r 59e032315ab9 pytask/middleware/exceptions.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pytask/middleware/exceptions.py Tue Feb 01 02:14:49 2011 +0530 @@ -0,0 +1,32 @@ +"""Module containing the middleware that processes exceptions for PyTask. +""" + +__authors__ = [ + '"Madhusudan.C.S" ', + ] + + +from django.http import HttpResponse +from django.template import loader +from django.template import RequestContext + +from pytask.helpers.exceptions import UnauthorizedAccess + + +class ExceptionMiddleware(object): + """Middleware definition that processes exceptions raised in PyTaskViews. + """ + + def process_exception(self, request, exception): + """Process the exception raised. + """ + + if isinstance(exception, UnauthorizedAccess): + template = loader.get_template('error.html') + context = RequestContext(request, { + 'error_message': exception.message + }) + return HttpResponse(template.render(context)) + + # let Django handle it + return None