Update middleware to new style classes

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-14 00:22:35 -04:00
parent 7752ca0f03
commit 9b2633e6c7
7 changed files with 13 additions and 8 deletions

View File

@@ -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)
===================

View File

@@ -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
--------

View File

@@ -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')

View File

@@ -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

View File

@@ -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)

View File

@@ -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',

View File

@@ -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',