Skip to main content

Django middleware that provides a maintenance countdown warning message.

Project description

Build Status Updates Code style: black

Python Versions Django Versions

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 Distribution

django_letsmaintain-1.0.5.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_letsmaintain-1.0.5-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file django_letsmaintain-1.0.5.tar.gz.

File metadata

  • Download URL: django_letsmaintain-1.0.5.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.12.8 Linux/6.1.0-28-amd64

File hashes

Hashes for django_letsmaintain-1.0.5.tar.gz
Algorithm Hash digest
SHA256 ade85713a816544d8d1aceb9b8800dd7a5e593c203449f8c34b8c5fafb71a8e8
MD5 1b13ccf44e3acbb896469e86306be291
BLAKE2b-256 1eaf41826ad21785eb1190a98d54e83e5fbef8f33f67e850420ea08d7a3f3434

See more details on using hashes here.

File details

Details for the file django_letsmaintain-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: django_letsmaintain-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.12.8 Linux/6.1.0-28-amd64

File hashes

Hashes for django_letsmaintain-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cd243ca320d4919893cc0ad6984e4e28bb034fec12d6286b9521bf48541557b5
MD5 fa3e45f372b72d967037272e88cb6aff
BLAKE2b-256 62b171738f0f152cb304c82483292f05896d14d656cfeadb5019df282ad47b48

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page