##// END OF EJS Templates
Get one ban object, not filter them
neko259 -
r2012:d33cae51 default
parent child Browse files
Show More
@@ -6,6 +6,8 b' from django.utils import timezone'
6 from boards import utils
6 from boards import utils
7 from boards.models import Ban
7 from boards.models import Ban
8
8
9 PATH_BANNED = '/banned/'
10
9 SESSION_TIMEZONE = 'django_timezone'
11 SESSION_TIMEZONE = 'django_timezone'
10
12
11 RESPONSE_CONTENT_TYPE = 'Content-Type'
13 RESPONSE_CONTENT_TYPE = 'Content-Type'
@@ -25,14 +27,15 b' class BanMiddleware:'
25 def __call__(self, request):
27 def __call__(self, request):
26 response = self.get_response(request)
28 response = self.get_response(request)
27
29
28 if request.path != '/banned/':
30 if request.path != PATH_BANNED:
29 ip = utils.get_client_ip(request)
31 ip = utils.get_client_ip(request)
30 bans = Ban.objects.filter(ip=ip)
32 try:
33 ban = Ban.objects.get(ip=ip)
31
34
32 if bans.exists():
33 ban = bans[0]
34 if not ban.can_read:
35 if not ban.can_read:
35 return redirect('banned')
36 return redirect('banned')
37 except Ban.DoesNotExist:
38 pass
36
39
37 return response
40 return response
38
41
General Comments 0
You need to be logged in to leave comments. Login now