##// END OF EJS Templates
Insert new posts in the pub time position instead of the end (js). Used when the posts are synced to the middle of the thread
Insert new posts in the pub time position instead of the end (js). Used when the posts are synced to the middle of the thread

File last commit:

r2018:9b956998 default
r2105:fd2a304e default
Show More
middlewares.py
42 lines | 1.0 KiB | text/x-python | PythonLexer
import pytz
from django.shortcuts import redirect
from django.utils import timezone
from django.utils.deprecation import MiddlewareMixin
from boards import utils
from boards.models import Ban
PATH_BANNED = '/banned/'
SESSION_TIMEZONE = 'django_timezone'
RESPONSE_CONTENT_TYPE = 'Content-Type'
TYPE_HTML = 'text/html'
class BanMiddleware(MiddlewareMixin):
"""
This is run before showing the thread. Banned users don't need to see
anything
"""
def process_request(self, request):
if request.path != PATH_BANNED:
ip = utils.get_client_ip(request)
try:
ban = Ban.objects.get(ip=ip)
if not ban.can_read:
return redirect('banned')
except Ban.DoesNotExist:
pass
class TimezoneMiddleware(MiddlewareMixin):
def process_request(self, request):
tzname = request.session.get(SESSION_TIMEZONE)
if tzname:
timezone.activate(pytz.timezone(tzname))
else:
timezone.deactivate()