minecraft_manager/middleware.py

17 lines
495 B
Python
Raw Permalink Normal View History

2018-09-20 02:56:17 +00:00
import pytz
from django.utils import timezone
from django.utils.deprecation import MiddlewareMixin
class TimezoneMiddleware(MiddlewareMixin):
def process_request(self, request):
tzname = request.session.get('django_timezone')
if tzname:
timezone.activate(pytz.timezone(tzname))
else:
try:
timezone.activate(pytz.timezone(request.user.usersettings.default_timezone))
except:
timezone.deactivate()