Django middleware that provides a maintenance countdown warning message.
Project description
django-letsmaintain
Django middleware that provides a maintenance countdown warning message.
This middleware searches the cache for the key maintenance_alert
. Its contents are expected to be a string representing an aware datetime in isoformat:
from datetime import datetime, timezone
the_time = datetime.now(timezone.utc).isoformat(timespec='minutes')
print(the_time)
Example result: '2020-06-24T12:00+00:00'
-
The middleware will raise a warning in all pages with a seconds countdown.
-
The last 60 seconds, the warning message will become an error message.
A bash script can invoke the relevant cache key:
#!/bin/bash
FIVE_MINUTES_LATER=$(date --date "$(date +%Y-%m-%dT%H:%M:%S%:z) +5 min" --iso-8601=minutes)
echo "from django.core.cache import cache; cache.set(\"maintenance_alert\", \"$FIVE_MINUTES_LATER\")" \
| ./manage.py shell
sleep 5m
# Redirect to maintenance.html
# nginx example: https://lincolnloop.com/blog/pro-tip-redirecting-custom-nginx-maintenance-page/
# <perform maintenance>
# Cancel redirect
Required Settings
The required settings for the middleware to operate are:
CACHES
TIME_ZONE
USE_TZ = True
- "letsmaintain" in
INSTALLED_APPS
- "letsmaintain.middleware.MaintenanceMiddleware" in
MIDDLEWARE
after "MessageMiddleware"
Tests
To run the tests:
- Install tox
- Define:
TOX_DB_NAME
,TOX_DB_USER
,TOX_DB_PASSWD
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for django_letsmaintain-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caca25022d935ec433f935984b5e55ce7c734aa2f3974921f3081608c8327dd1 |
|
MD5 | a47b1113912eb69d3119c33f26626033 |
|
BLAKE2b-256 | 1dec14a2d8426e3f2cace45a93dfd0348fe3cb150f35b15f516fb034b5849582 |