ADS System
[edumed.git] / forum / middleware.py
1 # -*- coding: utf-8 -*-
2 from urllib import urlencode
3
4 from django.contrib.auth import REDIRECT_FIELD_NAME
5 from django.http import HttpResponseRedirect
6 from django.core.urlresolvers import reverse
7 from django_cas.views import login as cas_login
8
9
10 class ForumMiddleware(object):
11     @staticmethod
12     def process_request(request):
13         if request.path.startswith(reverse('pybb:index')) \
14                 and (not hasattr(request, 'user') or not request.user.is_authenticated()):
15             params = urlencode({REDIRECT_FIELD_NAME: request.get_full_path()})
16             return HttpResponseRedirect(reverse(cas_login) + '?' + params)