pytask/middleware/exceptions.py
changeset 539 59e032315ab9
child 541 a1007eb3fff9
--- /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" <madhusudancs@fossee.in>',
+    ]
+
+
+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