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>
21 lines
578 B
Python
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()
|