diff --git a/HISTORY.rst b/HISTORY.rst index e33e907137..1b7ec55e03 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -49,6 +49,7 @@ * Increase the default number of recently added documents and recently accessed documents from 40 to 400. * Integrate django-autoadmin into the core apps. +* Update middleware to new style classes. 3.1.11 (2019-04-XX) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 1fc5b1d198..e8daf27a6f 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -73,6 +73,7 @@ Other changes * Increase the default number of recently added documents and recently accessed documents from 40 to 400. * Integrate django-autoadmin into the core apps. +* Update middleware to new style classes. Removals -------- diff --git a/mayan/apps/common/middleware/ajax_redirect.py b/mayan/apps/common/middleware/ajax_redirect.py index 24166d685a..b8ac222564 100644 --- a/mayan/apps/common/middleware/ajax_redirect.py +++ b/mayan/apps/common/middleware/ajax_redirect.py @@ -2,9 +2,10 @@ from __future__ import unicode_literals from django.conf import settings from django.http import HttpResponseRedirect +from django.utils.deprecation import MiddlewareMixin -class AjaxRedirect(object): +class AjaxRedirect(MiddlewareMixin): def process_request(self, request): ajax_referer = request.META.get('HTTP_X_ALT_REFERER') diff --git a/mayan/apps/common/middleware/error_logging.py b/mayan/apps/common/middleware/error_logging.py index a90490cb5c..e7ffaa0b9d 100644 --- a/mayan/apps/common/middleware/error_logging.py +++ b/mayan/apps/common/middleware/error_logging.py @@ -4,11 +4,12 @@ import logging from django.core.exceptions import PermissionDenied from django.http import Http404 +from django.utils.deprecation import MiddlewareMixin logger = logging.getLogger(__name__) -class ErrorLoggingMiddleware(object): +class ErrorLoggingMiddleware(MiddlewareMixin): def process_exception(self, request, exception): if not isinstance(exception, (PermissionDenied, Http404)): # Don't log non critical exceptions diff --git a/mayan/apps/common/middleware/timezone.py b/mayan/apps/common/middleware/timezone.py index 491abed3e2..cfc4119390 100644 --- a/mayan/apps/common/middleware/timezone.py +++ b/mayan/apps/common/middleware/timezone.py @@ -4,9 +4,10 @@ import pytz from django.conf import settings from django.utils import timezone +from django.utils.deprecation import MiddlewareMixin -class TimezoneMiddleware(object): +class TimezoneMiddleware(MiddlewareMixin): def process_request(self, request): if hasattr(request, 'session'): tzname = request.session.get(settings.TIMEZONE_SESSION_KEY) diff --git a/mayan/settings/base.py b/mayan/settings/base.py index 6a0c1aefe2..986f356a16 100644 --- a/mayan/settings/base.py +++ b/mayan/settings/base.py @@ -127,7 +127,7 @@ INSTALLED_APPS = ( 'drf_yasg', ) -MIDDLEWARE_CLASSES = ( +MIDDLEWARE = ( 'mayan.apps.common.middleware.error_logging.ErrorLoggingMiddleware', 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', diff --git a/mayan/settings/testing/base.py b/mayan/settings/testing/base.py index 4f5ad241ee..0b89bf6e0a 100644 --- a/mayan/settings/testing/base.py +++ b/mayan/settings/testing/base.py @@ -12,8 +12,8 @@ COMMON_PRODUCTION_ERROR_LOG_PATH = '/tmp/mayan-errors.log' # Remove whitenoise from middlewares. Causes out of memory errors during test # suit -MIDDLEWARE_CLASSES = [ - cls for cls in MIDDLEWARE_CLASSES if cls != 'whitenoise.middleware.WhiteNoiseMiddleware' +MIDDLEWARE = [ + cls for cls in MIDDLEWARE if cls != 'whitenoise.middleware.WhiteNoiseMiddleware' ] # User a simpler password hasher @@ -38,8 +38,8 @@ CELERY_EAGER_PROPAGATES_EXCEPTIONS = True BROKER_BACKEND = 'memory' # Remove middlewares not used for tests -MIDDLEWARE_CLASSES = [ - cls for cls in MIDDLEWARE_CLASSES if cls not in [ +MIDDLEWARE = [ + cls for cls in MIDDLEWARE if cls not in [ 'common.middleware.error_logging.ErrorLoggingMiddleware', 'django.middleware.security.SecurityMiddleware', 'corsheaders.middleware.CorsMiddleware',