From d434e95f4d73e9c7aeec0e880bf16b8c9482235c Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 15 Jul 2024 14:26:38 +0100 Subject: [PATCH] Add maintenance mode page --- app/__init__.py | 11 ++++++++++- app/templates/main/maintenance-mode.html | 24 ++++++++++++++++++++++++ config/envs/default.py | 3 +++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 app/templates/main/maintenance-mode.html diff --git a/app/__init__.py b/app/__init__.py index 33055ae..a592bfa 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,4 +1,4 @@ -from flask import Flask +from flask import Flask, render_template, request from flask_assets import Environment from fsd_utils import init_sentry from fsd_utils.healthchecks.checkers import FlaskRunningChecker @@ -52,6 +52,15 @@ def create_app(config_class=Config) -> Flask: ] ) + @app.before_request + def maintenance_page() -> str | None: + if request.endpoint != "static" and app.config["MAINTENANCE_MODE"]: + return render_template( + "main/maintenance-mode.html", maintenance_ends_from=app.config["MAINTENANCE_ENDS_FROM"] + ) + + return None + assets.init_app(app) static_assets.init_assets(app, auto_build=Config.AUTO_BUILD_ASSETS, static_folder="static/src") diff --git a/app/templates/main/maintenance-mode.html b/app/templates/main/maintenance-mode.html new file mode 100644 index 0000000..c4e61e6 --- /dev/null +++ b/app/templates/main/maintenance-mode.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} + +{% block pageTitle %}Sorry, the service is unavailable – {{ config['SERVICE_NAME'] }} – GOV.UK{% endblock pageTitle %} + +{# Override main width to two thirds #} +{% set mainClasses = "govuk-main-wrapper-l govuk-!-width-two-thirds" %} + +{% block content %} +
+

Sorry, the service is unavailable

+ + {% if maintenance_ends_from %} +

You will be able to use the service from {{ maintenance_ends_from }}

+ {% else %} +

You will be able to use the service later.

+ {% endif %} + +

+ If you need help, contact us at {{ config['CONTACT_EMAIL'] }}. + We aim to respond within 1 to 2 working days +

+

Do not send your data return or any attachments to this email address.

+
+{% endblock content %} diff --git a/config/envs/default.py b/config/envs/default.py index 24a29e2..311a116 100644 --- a/config/envs/default.py +++ b/config/envs/default.py @@ -13,6 +13,9 @@ class DefaultConfig(object): FLASK_ENV = CommonConfig.FLASK_ENV ENABLE_VALIDATION_LOGGING = os.environ.get("ENABLE_VALIDATION_LOGGING", False) + MAINTENANCE_MODE: bool = os.getenv("MAINTENANCE_MODE", "false").lower() in {"1", "true", "yes", "y", "on"} + MAINTENANCE_ENDS_FROM: str | None = os.getenv("MAINTENANCE_ENDS_FROM") + CONTACT_EMAIL = os.environ.get("CONTACT_EMAIL", "fsd.support@levellingup.gov.uk") CONTACT_PHONE = os.environ.get("CONTACT_PHONE", "12345678910") DEPARTMENT_NAME = os.environ.get("DEPARTMENT_NAME", "Department for Levelling Up, Housing and Communities")