| author | gibus |
| Mon, 14 May 2012 16:01:30 +0200 | |
| changeset 429 | fc7477d34489 |
| parent 285 | 1070d52adc11 |
| child 475 | 782d40ecf7c3 |
| permissions | -rw-r--r-- |
| 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 |
|
|
285
1070d52adc11
propagates query string parameters when login in (so that link with direct coment id are properly propagated)
raph
parents:
0
diff
changeset
|
5 |
from urllib import urlencode |
| 0 | 6 |
|
7 |
class CmMiddleware(object): |
|
8 |
||
9 |
def process_exception(self, request, exception): |
|
10 |
if settings.DEBUG: |
|
11 |
import sys, traceback |
|
12 |
traceback.print_exc() |
|
13 |
if type(exception) == UnauthorizedException: |
|
14 |
if request.user.is_anonymous(): |
|
|
285
1070d52adc11
propagates query string parameters when login in (so that link with direct coment id are properly propagated)
raph
parents:
0
diff
changeset
|
15 |
query = urlencode({'next': request.META['PATH_INFO'], 'q' : request.META['QUERY_STRING'] }) |
|
1070d52adc11
propagates query string parameters when login in (so that link with direct coment id are properly propagated)
raph
parents:
0
diff
changeset
|
16 |
login_url = reverse('login') + '?' + query |
| 0 | 17 |
return HttpResponseRedirect(login_url) |
18 |
else: |
|
19 |
redirect_url = reverse('unauthorized') |
|
20 |
return HttpResponseRedirect(redirect_url) |
|
21 |
raise |