1 from cm.exception import UnauthorizedException |
1 from cm.exception import UnauthorizedException |
2 from django.conf import settings |
2 from django.conf import settings |
3 from django.http import HttpResponseServerError,HttpResponseRedirect |
3 from django.http import HttpResponseServerError,HttpResponseRedirect |
4 from django.core.urlresolvers import reverse |
4 from django.core.urlresolvers import reverse |
|
5 from urllib import urlencode |
5 |
6 |
6 class CmMiddleware(object): |
7 class CmMiddleware(object): |
7 |
8 |
8 def process_exception(self, request, exception): |
9 def process_exception(self, request, exception): |
9 if settings.DEBUG: |
10 if settings.DEBUG: |
10 import sys, traceback |
11 import sys, traceback |
11 traceback.print_exc() |
12 traceback.print_exc() |
12 if type(exception) == UnauthorizedException: |
13 if type(exception) == UnauthorizedException: |
13 if request.user.is_anonymous(): |
14 if request.user.is_anonymous(): |
14 login_url = reverse('login') + '?next=%s' %request.META['PATH_INFO'] |
15 query = urlencode({'next': request.META['PATH_INFO'], 'q' : request.META['QUERY_STRING'] }) |
|
16 login_url = reverse('login') + '?' + query |
15 return HttpResponseRedirect(login_url) |
17 return HttpResponseRedirect(login_url) |
16 else: |
18 else: |
17 redirect_url = reverse('unauthorized') |
19 redirect_url = reverse('unauthorized') |
18 return HttpResponseRedirect(redirect_url) |
20 return HttpResponseRedirect(redirect_url) |
19 raise |
21 raise |