##// END OF EJS Templates
Need to manually join lazy strings in authors now
Need to manually join lazy strings in authors now

File last commit:

r1986:0b41439a default
r1990:9be6ed3d default
Show More
middlewares.py
54 lines | 1.2 KiB | text/x-python | PythonLexer
import pytz
from django.shortcuts import redirect
from django.utils import timezone
from boards import utils
from boards.models import Ban
SESSION_TIMEZONE = 'django_timezone'
RESPONSE_CONTENT_TYPE = 'Content-Type'
TYPE_HTML = 'text/html'
class BanMiddleware:
"""
This is run before showing the thread. Banned users don't need to see
anything
"""
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
if request.path != '/banned/':
ip = utils.get_client_ip(request)
bans = Ban.objects.filter(ip=ip)
if bans.exists():
ban = bans[0]
if not ban.can_read:
return redirect('banned')
return response
class TimezoneMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
tzname = request.session.get(SESSION_TIMEZONE)
if tzname:
timezone.activate(pytz.timezone(tzname))
else:
timezone.deactivate()
return response