forked from ccnmtl/mediathread
-
Notifications
You must be signed in to change notification settings - Fork 0
/
someutils.py
executable file
·49 lines (38 loc) · 1.63 KB
/
someutils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!ve/bin/python
try:
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponseNotAllowed
from django.http import HttpResponse
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.utils.http import urlquote
from django.http import HttpResponseRedirect
def match_path(path,config_string):
config_list = getattr(settings, config_string, [])
for p in config_list:
if isinstance(p,str) and path.startswith(p):
return True
elif hasattr(p,'match') and p.match(path):
return True
return False
class AuthRequirementMiddleware(object):
def process_request(self, request):
path = urlquote(request.get_full_path())
if request.user.is_authenticated():
return None
if match_path(path,'ANONYMOUS_PATHS'):
return None
if hasattr(settings,'NON_ANONYMOUS_PATHS') \
and not match_path(path,'NON_ANONYMOUS_PATHS'):
return None
#from django.shortcuts import get_object_or_404
#request.coursename = "A&HW 5050 - Special Topics: Vietnam Now!"
# CUcourse_A&HWY5050_001_2009_2
#request.course = Group.objects.get_or_create(name='summer09')[0]
return HttpResponseRedirect('%s?%s=%s' % (
settings.LOGIN_URL,
REDIRECT_FIELD_NAME,
path))
except ImportError:
pass