Skip to content

Commit

Permalink
feat: Toggle for maintenance mode
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Feb 5, 2025
1 parent 5f742ee commit 9bd6d97
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
25 changes: 25 additions & 0 deletions deploy/middleware/maintenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.http import HttpResponseRedirect
from django.urls import reverse, reverse_lazy


class MaintenanceMiddleware(object):
"""
This middleware allows us to turn on "Maintenance Mode". Toggle `MAINTENANCE_MODE` to True in
`process_view` to redirect all requests in the app to the maintenance holding page.
"""

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
response = self.get_response(request)
return response

def process_view(self, request, callback, callback_args, callback_kwargs):
MAINTENANCE_MODE = False

if MAINTENANCE_MODE and not request.path.startswith(reverse("maintenance")):
return HttpResponseRedirect(reverse_lazy("maintenance"))

Check warning on line 22 in deploy/middleware/maintenance.py

View check run for this annotation

Codecov / codecov/patch

deploy/middleware/maintenance.py#L22

Added line #L22 was not covered by tests

if not MAINTENANCE_MODE and request.path.startswith(reverse("maintenance")):
return HttpResponseRedirect(reverse_lazy("home"))

Check warning on line 25 in deploy/middleware/maintenance.py

View check run for this annotation

Codecov / codecov/patch

deploy/middleware/maintenance.py#L25

Added line #L25 was not covered by tests
1 change: 1 addition & 0 deletions example_project/portal_test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"preventconcurrentlogins.middleware.PreventConcurrentLoginsMiddleware",
"csp.middleware.CSPMiddleware",
"deploy.middleware.screentime_warning.ScreentimeWarningMiddleware",
"deploy.middleware.maintenance.MaintenanceMiddleware",
]

TEMPLATES = [
Expand Down
1 change: 1 addition & 0 deletions example_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"preventconcurrentlogins.middleware.PreventConcurrentLoginsMiddleware",
"csp.middleware.CSPMiddleware",
"deploy.middleware.screentime_warning.ScreentimeWarningMiddleware",
"deploy.middleware.maintenance.MaintenanceMiddleware",
]

TEMPLATES = [
Expand Down
34 changes: 34 additions & 0 deletions portal/templates/maintenance.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% load static %}
{% load app_tags %}
<!DOCTYPE html>
<html>
<head>
<title>Code For Life - maintenance</title>
<link rel="stylesheet" type="text/css" href="{% static 'portal.css' %}">
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
<link rel="shortcut icon" href="{% static 'portal/img/favicon.ico' %}" type="image/x-icon">
<link rel="icon" href="{% static 'portal/img/favicon.ico' %}" type="image/x-icon">
</head>
<body>
<div class="content-footer-wrapper">
<div id="contentWrapper">
{% block topBar %}
{% include 'portal/partials/header.html' %}
{% endblock topBar %}
<div class="content">
<div class="error-page background container">
<div class="row mx-0 d-flex justify-content-between">
<div class="flex-grow-1">
<h2>Works in progress!</h2>
<h5>Apologies! Dee is working on something important.</h5>
<p>The website is temporarily unavailable.</p>
</div>
<img title="Dee" alt="Dee" src="{% static 'portal/img/dee.png' %}"/>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
5 changes: 5 additions & 0 deletions portal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,9 @@
name="remove_fake_accounts",
),
re_path(r"^celebrate/", ten_year_map_page, name="celebrate"),
re_path(
r"^maintenance/$",
TemplateView.as_view(template_name="maintenance.html"),
name="maintenance",
),
]

0 comments on commit 9bd6d97

Please sign in to comment.