We’ll be back soon!
++ Sorry for the inconvenience but we’re performing some maintenance at the moment. We’ll be back online shortly! +
+— The Team
+diff --git a/apis_core/core/middleware.py b/apis_core/core/middleware.py new file mode 100644 index 000000000..c4ad034d9 --- /dev/null +++ b/apis_core/core/middleware.py @@ -0,0 +1,24 @@ +import logging +from pathlib import Path + +from django.conf import settings +from django.shortcuts import render + +logger = logging.getLogger(__name__) + + +class MaintenanceMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + maintenance_file = getattr( + settings, "APIS_MAINTENANCE_FILE", "apis_maintenance" + ) + if Path(maintenance_file).exists(): + logger.warning("Site is running in maintenance mode") + if hasattr(request, "user"): + if request.user.is_superuser: + return self.get_response(request) + return render(request, "maintenance.html") + return self.get_response(request) diff --git a/apis_core/core/static/css/maintenance.css b/apis_core/core/static/css/maintenance.css new file mode 100644 index 000000000..ac9b25d7b --- /dev/null +++ b/apis_core/core/static/css/maintenance.css @@ -0,0 +1,20 @@ +body { + text-align: center; + padding: 150px; +} + +h1 { + font-size: 50px; +} + +body { + font: 20px Helvetica, sans-serif; + color: #333; +} + +article { + display: block; + text-align: left; + width: 650px; + margin: 0 auto; +} diff --git a/apis_core/core/templates/maintenance.html b/apis_core/core/templates/maintenance.html new file mode 100644 index 000000000..0c555a1f5 --- /dev/null +++ b/apis_core/core/templates/maintenance.html @@ -0,0 +1,20 @@ + +{% load static %} + + +
+ ++ Sorry for the inconvenience but we’re performing some maintenance at the moment. We’ll be back online shortly! +
+— The Team
+