from django http import HttpResponseRedirect class UserDomain object d

 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
from django.http import HttpResponseRedirect
class UserDomain(object):
def process_request(self, request):
head, neck, tail = request.META['HTTP_HOST'].split('.', 2)
if neck == 'at':
if request.path.startswith('/~/'):
if not request.user.is_authenticated():
return HttpResponseRedirect('http://at.mymcomm.net/accounts/login/')
return HttpResponseRedirect( "http://%s.at.mymcomm.net/%s" % (request.user.username,
request.path.replace('/~/', '', 1)))
elif request.path.startswith('/~'):
user, path = request.path.replace('/~', '', 1).split('/', 1)
return HttpResponseRedirect("http://%s.at.mymcomm.net/%s" % (user, path))
else:
request.path = "/~%s%s" % (head, request.path)
elif head == 'at' and request.path.startswith('/~'):
user, path = request.path.replace('/~', '', 1).split('/', 1)
if user:
return HttpResponseRedirect("http://%s.at.mymcomm.net/%s" % (user, path))
elif request.user.is_authenticated():
return HttpResponseRedirect("http://%s.at.mymcomm.net/%s" % (request.user.username, path))
else:
return HttpResponseRedirect('http://at.mymcomm.net/accounts/login/')