|
1 | 1 | import re
|
2 | 2 | from django import VERSION as django_version
|
3 | 3 | from django.conf import urls
|
| 4 | +from django.core.exceptions import MiddlewareNotUsed |
4 | 5 | from django.urls import get_resolver
|
5 | 6 | from django.urls import resolvers
|
6 | 7 | from django.utils.deprecation import MiddlewareMixin
|
|
15 | 16 | DJANGO_VERSION_MAJOR = django_version[0]
|
16 | 17 | DJANGO_VERSION_MINOR = django_version[1]
|
17 | 18 |
|
| 19 | + |
18 | 20 | class MaintenanceModeMiddleware(MiddlewareMixin):
|
| 21 | + def __init__(self, get_response): |
| 22 | + if settings.MAINTENANCE_ONLY_EVALUATE_DURING_RELOAD and not maintenance.status(): |
| 23 | + raise MiddlewareNotUsed() |
| 24 | + |
| 25 | + super().__init__(get_response=get_response) |
| 26 | + |
19 | 27 | def process_request(self, request):
|
20 | 28 | # Allow access if middleware is not activated
|
21 | 29 | allow_staff = getattr(settings, "MAINTENANCE_ALLOW_STAFF", True)
|
22 | 30 | allow_superuser = getattr(settings, "MAINTENANCE_ALLOW_SUPERUSER", True)
|
23 | 31 |
|
24 |
| - if not (settings.MAINTENANCE_MODE or maintenance.status()): |
| 32 | + if not maintenance.status(): |
25 | 33 | return None
|
26 | 34 |
|
27 | 35 | INTERNAL_IPS = maintenance.IPList(settings.INTERNAL_IPS)
|
@@ -66,4 +74,3 @@ def process_request(self, request):
|
66 | 74 | callback = resolve('503')
|
67 | 75 |
|
68 | 76 | return callback(request)
|
69 |
| - |
|
0 commit comments