Skip to content

Commit cccaabf

Browse files
committed
- Renamed MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT setting to MAINTENANCE_MODE_GET_CONTEXT.
1 parent ab1fcf6 commit cccaabf

File tree

3 files changed

+21
-32
lines changed

3 files changed

+21
-32
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ Retrieve user's real IP address using [`django-ipware`](https://github.com/un33k
113113
MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS = "ipware.ip.get_ip"
114114
```
115115

116+
```python
117+
# the path of the function that will return the response context -> 'myapp.mymodule.myfunction'
118+
MAINTENANCE_MODE_GET_CONTEXT = None
119+
```
120+
116121
```python
117122
# list of urls that will not be affected by the maintenance-mode
118123
# urls will be used to compile regular expressions objects
@@ -145,11 +150,6 @@ MAINTENANCE_MODE_RESPONSE_TYPE = "html"
145150
MAINTENANCE_MODE_TEMPLATE = "503.html"
146151
```
147152

148-
```python
149-
# the path of the function that will return the template context -> 'myapp.mymodule.myfunction'
150-
MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = None
151-
```
152-
153153
```python
154154
# the HTTP status code to send
155155
MAINTENANCE_MODE_STATUS_CODE = 503

maintenance_mode/http.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616

1717
def get_maintenance_response_context(request):
1818
context = {}
19-
if settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT:
19+
if settings.MAINTENANCE_MODE_GET_CONTEXT:
2020
try:
2121
get_request_context_func = import_string(
22-
settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT
22+
settings.MAINTENANCE_MODE_GET_CONTEXT
2323
)
2424
except ImportError as error:
2525
raise ImproperlyConfigured(
26-
"settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT "
27-
"is not a valid function path."
26+
"settings.MAINTENANCE_MODE_GET_CONTEXT is not a valid function path."
2827
) from error
2928

3029
context = get_request_context_func(request=request)

tests/tests.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_client_ip_address(request):
4040

4141

4242
def get_template_context(request):
43-
return {"TEST_MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT": True}
43+
return {"TEST_MAINTENANCE_MODE_GET_CONTEXT": True}
4444

4545

4646
@override_settings(
@@ -961,44 +961,38 @@ def test_middleware_get_template_context(self):
961961

962962
settings.MAINTENANCE_MODE = True
963963

964-
settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = (
965-
"tests.tests.get_template_context"
966-
)
964+
settings.MAINTENANCE_MODE_GET_CONTEXT = "tests.tests.get_template_context"
967965
response = self.client.get("/")
968-
val = response.context.get("TEST_MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT", False)
966+
val = response.context.get("TEST_MAINTENANCE_MODE_GET_CONTEXT", False)
969967
self.assertTrue(val)
970968

971969
get_template_context_error = False
972970
try:
973-
settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = (
971+
settings.MAINTENANCE_MODE_GET_CONTEXT = (
974972
"tests.tests_invalid.get_template_context_invalid"
975973
)
976974
response = self.client.get("/")
977-
val = response.context.get(
978-
"TEST_MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT", False
979-
)
975+
val = response.context.get("TEST_MAINTENANCE_MODE_GET_CONTEXT", False)
980976
self.assertFalse(val)
981977
except ImproperlyConfigured:
982978
get_template_context_error = True
983979
self.assertTrue(get_template_context_error)
984980

985981
get_template_context_error = False
986982
try:
987-
settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = (
983+
settings.MAINTENANCE_MODE_GET_CONTEXT = (
988984
"tests.tests.get_template_context_invalid"
989985
)
990986
response = self.client.get("/")
991-
val = response.context.get(
992-
"TEST_MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT", False
993-
)
987+
val = response.context.get("TEST_MAINTENANCE_MODE_GET_CONTEXT", False)
994988
self.assertFalse(val)
995989
except ImproperlyConfigured:
996990
get_template_context_error = True
997991
self.assertTrue(get_template_context_error)
998992

999-
settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = None
993+
settings.MAINTENANCE_MODE_GET_CONTEXT = None
1000994
response = self.client.get("/")
1001-
val = response.context.get("TEST_MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT", False)
995+
val = response.context.get("TEST_MAINTENANCE_MODE_GET_CONTEXT", False)
1002996
self.assertFalse(val)
1003997

1004998
def test_middleware_response_type(self):
@@ -1084,7 +1078,7 @@ def tearDown(self):
10841078
# Clean up settings
10851079
settings.MAINTENANCE_MODE_REDIRECT_URL = None
10861080
settings.MAINTENANCE_MODE_TEMPLATE = "503.html"
1087-
settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = None
1081+
settings.MAINTENANCE_MODE_GET_CONTEXT = None
10881082

10891083
def test_redirect(self):
10901084
settings.MAINTENANCE_MODE_REDIRECT_URL = "http://redirect.example.cz/"
@@ -1096,7 +1090,7 @@ def test_redirect(self):
10961090

10971091
def test_no_context(self):
10981092
settings.MAINTENANCE_MODE_TEMPLATE = "503.html"
1099-
settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = None
1093+
settings.MAINTENANCE_MODE_GET_CONTEXT = None
11001094

11011095
response = http.get_maintenance_response(RequestFactory().get("/dummy/"))
11021096

@@ -1109,9 +1103,7 @@ def test_no_context(self):
11091103

11101104
def test_custom_context(self):
11111105
settings.MAINTENANCE_MODE_TEMPLATE = "503.html"
1112-
settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = (
1113-
"tests.tests.get_template_context"
1114-
)
1106+
settings.MAINTENANCE_MODE_GET_CONTEXT = "tests.tests.get_template_context"
11151107

11161108
response = http.get_maintenance_response(RequestFactory().get("/dummy/"))
11171109

@@ -1123,9 +1115,7 @@ def test_custom_context(self):
11231115
self.assertIn("max-age=0", response["Cache-Control"])
11241116

11251117
def test_invalid_context_function(self):
1126-
settings.MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = (
1127-
"invalid.invalid-context-function"
1128-
)
1118+
settings.MAINTENANCE_MODE_GET_CONTEXT = "invalid.invalid-context-function"
11291119

11301120
self.assertRaisesMessage(
11311121
ImproperlyConfigured,

0 commit comments

Comments
 (0)