From 625c67d222c6d76caa3629d9ee562966fa1d649a Mon Sep 17 00:00:00 2001 From: Fabio Caccamo Date: Wed, 8 Dec 2021 16:24:32 +0100 Subject: [PATCH] Updated middleware for django 4.0 compatibility. --- maintenance_mode/middleware.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/maintenance_mode/middleware.py b/maintenance_mode/middleware.py index b44577e..d15e9f3 100644 --- a/maintenance_mode/middleware.py +++ b/maintenance_mode/middleware.py @@ -1,22 +1,21 @@ # -*- coding: utf-8 -*- -import django - -if django.VERSION < (1, 10): - __MaintenanceModeMiddlewareBaseClass = object -else: - # https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware - from django.utils.deprecation import MiddlewareMixin - __MaintenanceModeMiddlewareBaseClass = MiddlewareMixin - from maintenance_mode.http import ( get_maintenance_response, need_maintenance_response, ) -class MaintenanceModeMiddleware(__MaintenanceModeMiddlewareBaseClass): +class MaintenanceModeMiddleware(object): + + def __init__(self, get_response=None): + self.get_response = get_response + + def __call__(self, request): + response = self.process_request(request) + if response is None and callable(self.get_response): + response = self.get_response(request) + return response def process_request(self, request): if need_maintenance_response(request): return get_maintenance_response(request) - else: - return None + return None