From 0601a39829b4163652bada35cd813b6156b077dd Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 27 May 2024 17:37:30 +0200 Subject: [PATCH] feat: add dev mode warning and styling Introduced a development mode toggle for the app, which, when enabled, displays a distinctive warning on every page to inform users they are viewing a development version of the site. This warning is styled for clear visibility. Development mode is toggled with a new `--dev` command line argument or by setting an environment variable. The change aims to prevent confusion between the development and production environments for both developers and early users. - Added new CSS rules for a warning alert style in `base.css`. - Modified `main.py` to check for a development mode flag and pass a warning message to the template if the flag is set. - Updated `base.html` to include the warning message when present. - Added a new template for the development warning message. --- assets/css/base.css | 19 +++++++++++++++++++ main.py | 20 +++++++++++++++++++- templates/base.html | 1 + templates/prod-warning.html | 6 ++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 templates/prod-warning.html diff --git a/assets/css/base.css b/assets/css/base.css index 6916ad1..6bb4bc4 100644 --- a/assets/css/base.css +++ b/assets/css/base.css @@ -99,6 +99,25 @@ h5 { border-bottom: 1px solid #e0e0e0; } +.alert-warning { + background-color: #fff3cd; + border-color: #ffeeba; + color: #856404; + padding: 15px; + margin-bottom: 20px; + border-radius: 4px; +} + +.alert-warning .alert-link { + color: #856404; + font-weight: bold; + text-decoration: underline; +} + +.alert-warning .alert-link:hover { + color: #604c2e; +} + /* Responsive Styles */ @media (max-width: 768px) { .navbar .container { diff --git a/main.py b/main.py index f42bc36..221227b 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ from jinja2 import TemplateNotFound import json import pathlib +import os from argparse import ArgumentParser @@ -21,15 +22,32 @@ def catch_all(path): services = json.loads( (pathlib.Path(__file__).parent / "services.json").read_text() ) - return render_template(f"{path}.html", services=services) + + warning = None + + if app.development_mode: + warning = render_template("prod-warning.html") + + return render_template( + f"{path}.html", services=services, warning=warning + ) except TemplateNotFound: return "404 Not Found", 404 +app.development_mode = False + +if os.environ.get("PRIVATECOFFEE_DEV"): + app.development_mode = True + + if __name__ == "__main__": parser = ArgumentParser(description="Run the private.coffee web server.") parser.add_argument("--port", type=int, default=9810) parser.add_argument("--debug", action="store_true") + parser.add_argument("--dev", action="store_true") args = parser.parse_args() + app.development_mode = args.dev or app.development_mode + app.run(port=args.port, debug=args.debug) diff --git a/templates/base.html b/templates/base.html index d759727..13593f7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -51,6 +51,7 @@ JOIN & REBEL + {% if warning %}{{ warning|safe }}{% endif %} {% block content %}{% endblock %}