wiz попросил закинуть

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
class RedirectMiddleware(object):
def process_request(self, request):
if request.is_ajax():
return None
try:
site = Site.objects.get_current()
except:
return None
host = request.get_host()
if host != site.domain:
if host.endswith('.' + site.domain):
subdomain = host.replace('.' + site.domain, '')
if subdomain not in settings.DENIED_SUBDOMAINS:
try:
callback, callback_args, callback_kwargs = resolve(request.path, settings.SUBDOMAINS_ROOT_URLCONF)
except:
return HttpResponseRedirect('http://' + site.domain + request.path)
else:
callback_kwargs.update({'user': subdomain})
return callback(request, *callback_args, **callback_kwargs)
return HttpResponseRedirect('http://' + site.domain + request.path)