src/cm/middleware.py
author rbernard
Fri, 05 Feb 2010 18:43:58 +0100
changeset 154 8cb89c153140
parent 0 40c8f766c9b8
child 285 1070d52adc11
permissions -rw-r--r--
bug fix: removed \r in textversion's content because of a comment position bug in pre_edit. Added a save function to TextVersionManager to do so. Also removed cleaning \r before computing diffs because it should not be necessary anymore.

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

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():
                login_url = reverse('login') + '?next=%s' %request.META['PATH_INFO']
                return HttpResponseRedirect(login_url)
            else:
                redirect_url = reverse('unauthorized')
                return HttpResponseRedirect(redirect_url)
        raise