Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #170 from communitiesuk/maintenance-page
Browse files Browse the repository at this point in the history
Add maintenance mode page
  • Loading branch information
samuelhwilliams authored Jul 16, 2024
2 parents c373d56 + d434e95 commit a700bda
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand Down
24 changes: 24 additions & 0 deletions app/templates/main/maintenance-mode.html
Original file line number Diff line number Diff line change
@@ -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 %}
<div class="govuk-width-container">
<h1 class="govuk-heading-l">Sorry, the service is unavailable</h1>

{% if maintenance_ends_from %}
<p class="govuk-body">You will be able to use the service from {{ maintenance_ends_from }}</p>
{% else %}
<p class="govuk-body">You will be able to use the service later.</p>
{% endif %}

<p class="govuk-body">
If you need help, contact us at <a class="govuk-link" href="mailto:{{ config['CONTACT_EMAIL'] }}">{{ config['CONTACT_EMAIL'] }}</a>.
We aim to respond within 1 to 2 working days
</p>
<p class="govuk-body">Do not send your data return or any attachments to this email address.</p>
</div>
{% endblock content %}
3 changes: 3 additions & 0 deletions config/envs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a700bda

Please sign in to comment.