Files
mayan-edms/mayan/apps/common/middleware/timezone.py
Roberto Rosario 8e896a54f9 Middleware: Modernize middleware classes
Make the custom middleware provided by Mayan to use the
MiddlewareMixin provide by Django. This make the middleware
classes behave like classes or callables. This change ensures
compatibility with Django 2.x.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
2018-11-25 00:59:39 -04:00

21 lines
578 B
Python

from __future__ import unicode_literals
import pytz
from django.conf import settings
from django.utils import timezone
from django.utils.deprecation import MiddlewareMixin
class TimezoneMiddleware(MiddlewareMixin):
def process_request(self, request):
if hasattr(request, 'session'):
tzname = request.session.get(settings.TIMEZONE_SESSION_KEY)
else:
tzname = request.COOKIES.get(settings.TIMEZONE_COOKIE_NAME)
if tzname:
timezone.activate(pytz.timezone(tzname))
else:
timezone.deactivate()