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