##// END OF EJS Templates
Administration for sync sources. Now sync is available from the admin site instead of manual command line arguments. Still need to invoke sync_with_server by cron/timer
Administration for sync sources. Now sync is available from the admin site instead of manual command line arguments. Still need to invoke sync_with_server by cron/timer

File last commit:

r2018:9b956998 default
r2123:be532800 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()