From bfec2a647722e720168f55548855c5b1a96c1ebd Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 15 Jul 2024 14:28:43 +0100 Subject: [PATCH] Add maintenance mode page --- app/__init__.py | 11 +++++++++- app/templates/base.html | 2 ++ app/templates/main/maintenance-mode.html | 26 ++++++++++++++++++++++++ config/envs/default.py | 4 ++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 app/templates/main/maintenance-mode.html diff --git a/app/__init__.py b/app/__init__.py index dcfcab6..f31ca4e 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 flask_talisman import Talisman from flask_wtf.csrf import CSRFProtect @@ -47,6 +47,15 @@ def create_app(config_class=Config): ], } + @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 + # Initialise app extensions app.static_folder = "static/dist/" assets.init_app(app) diff --git a/app/templates/base.html b/app/templates/base.html index 4971618..cacc191 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -37,6 +37,7 @@ }) }} {% endblock phaseBanner %} + {% block backLinks %}
{% if request.path not in [url_for('main.download'), url_for('main.start_page')] %} {{ govukBackLink({ @@ -50,6 +51,7 @@ Log out
+ {% endblock backLinks %} {% endblock beforeContent %} {% block content %} diff --git a/app/templates/main/maintenance-mode.html b/app/templates/main/maintenance-mode.html new file mode 100644 index 0000000..605ed30 --- /dev/null +++ b/app/templates/main/maintenance-mode.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} + +{% block pageTitle %}Sorry, the service is unavailable – {{ config['SERVICE_NAME'] }} – GOV.UK{% endblock pageTitle %} + +{% block backLinks %}{% endblock backLinks %} + +{# 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 c3adce8..548fb1b 100644 --- a/config/envs/default.py +++ b/config/envs/default.py @@ -11,6 +11,10 @@ class DefaultConfig(object): FLASK_ROOT = str(Path(__file__).parent.parent.parent) FLASK_ENV = CommonConfig.FLASK_ENV FSD_LOG_LEVEL = logging.INFO + + 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").lower() CONTACT_PHONE = os.environ.get("CONTACT_PHONE", "12345678910") DEPARTMENT_NAME = os.environ.get("DEPARTMENT_NAME", "Department for Levelling Up, Housing and Communities")