coding utf-8 import urlparse from django conf import settings from dja

 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
# -*- coding: utf-8 -*-
import urlparse
from django.conf import settings
from django.http import HttpResponseRedirect, HttpResponseNotFound
from sat.models import Sat
class SatMiddleware(object):
def process_request(self,request):
request.sat = None
if request.path.startswith('/admin'):
return None
parts = request.get_host().rsplit(':', 1)
if len(parts) == 2:
host, port = parts
else:
host = parts[0]
port = None
# In debug server use debug sat instance
if port:
sat = Sat.objects.get(pk=settings.DEBUG_SAT_ID)
else:
try:
sat = Sat.objects.get(host=host)
except Sat.DoesNotExist:
return HttpResponseNotFound('Account is suspended')
request.sat = sat
return None