-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated middleware for django 4.0 compatibility.
- Loading branch information
1 parent
9f7f144
commit 625c67d
Showing
1 changed file
with
11 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |