src/cm/middleware.py
author Simon Descarpentries <sid1@sopinspace.com>
Fri, 05 Aug 2011 10:52:08 +0200
changeset 370 93c6ef9d7edf
parent 285 1070d52adc11
child 475 782d40ecf7c3
permissions -rw-r--r--
Revision of spanish translation. No more fuzzy strings (-63). No more empty translations (-91). Fuzzy strings are automatically added when source string change in code. Fuzzy strings must be regularly reviewed.

from cm.exception import UnauthorizedException 
from django.conf import settings
from django.http import HttpResponseServerError,HttpResponseRedirect
from django.core.urlresolvers import reverse
from urllib import urlencode

class CmMiddleware(object):
    
    def process_exception(self, request, exception):
        if settings.DEBUG:
            import sys, traceback
            traceback.print_exc()
        if type(exception) == UnauthorizedException:
            if request.user.is_anonymous():
                query = urlencode({'next': request.META['PATH_INFO'], 'q' : request.META['QUERY_STRING'] })
                login_url = reverse('login') + '?'  + query
                return HttpResponseRedirect(login_url)
            else:
                redirect_url = reverse('unauthorized')
                return HttpResponseRedirect(redirect_url)
        raise