Show a floating notice banner above the Django admin interface
Project description
Django Admin Notice
Show a floating notice banner above the Django admin interface. Particularly useful for indicating the current deployment environment.
Installation
Install django-admin-notice via the Python Package Index (PyPI):
pip install django-admin-notice
Add admin_notice
to your INSTALLED_APPS
somewhere before django.contrib.admin
.
# yourproject/settings.py
INSTALLED_APPS = [
# ... other apps
"admin_notice", # <-- Add this somewhere before "django.contrib.admin"
"django.contrib.admin",
# ... other apps
]
Add admin_notice.context_processors.notice
to the templates context_processors
.
Having django.template.context_processors.request
is required as well.
# yourproject/settings.py
TEMPLATES = [
{
"OPTIONS": {
"context_processors": [
# ... other context processors
"django.template.context_processors.request", # <-- have this
"admin_notice.context_processors.notice", # <-- Add this
# ... other context processors
]
},
},
]
Configuration
Set the ADMIN_NOTICE_TEXT
to the text you want to show above the admin interface.
No message is shown if this setting is missing or empty.
# yourproject/settings.py
ADMIN_NOTICE_TEXT = "Production environment"
Optionally specify a custom text color and background for your notice.
The default text color is white
and the default background red
.
# yourproject/settings.py
ADMIN_NOTICE_TEXT_COLOR = "white"
ADMIN_NOTICE_BACKGROUND = "red"
Tips
It's a common use case to indicate the projects deployment environment.
The following configuration shows how to obtain the django-admin-notice
configuration from environment variables and how to configure a fallback.
# yourproject/settings.py
from os import environ
ADMIN_NOTICE_TEXT = environ.get("ADMIN_NOTICE_TEXT", "Local environment")
ADMIN_NOTICE_TEXT_COLOR = environ.get("ADMIN_NOTICE_TEXT_COLOR", "white")
ADMIN_NOTICE_BACKGROUND = environ.get("ADMIN_NOTICE_BACKGROUND", "green")
Example
Run python manage.py runserver
after following the Installation section
to see a fully working example project.
Contributing
Setup
- Clone the repository and enter the cloned folder
- (optional) Create and activate a dedicated Python virtual environment
- Run
pip install -e ".[dev]"
to install the projects requirements - (optional) Run
pre-commit install
to install the pre-commit hook
Pre-commit hook
Our pre-commit hook formats and lints the code.
Formatting and linting
- Run
black admin_notice tests
to format the code - Run
flake8 admin_notice tests
to lint the code
Testing
- Run
py.test --cov admin_notice tests
to run the tests in the current Python env - Run
tox
to run the tests in all supported Python and Django environments
Makefile
All commands listed above have shortcut make recipes.
Take a look at the Makefile
to learn more.
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
Built Distribution
Hashes for django-admin-notice-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61971b4a0ae3c9188070d2f792e52bfc031936d4694d1c72335437f232c21f12 |
|
MD5 | 1b4fa5e60a1732734f67604c41053b93 |
|
BLAKE2b-256 | 709dd7597536832af3232e1c9d82e3d32286a87aef1f0901619443f35497ee46 |
Hashes for django_admin_notice-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54339199806e68f06fd1715757687368abcf0650aa08ee12dba095ff4a9813b9 |
|
MD5 | 52ac336f5c382a8f3f199407c9c8181d |
|
BLAKE2b-256 | e2e03a7d209a75f495aef58388385222c03d4d32c3d28ab8ee7e08a02ec9d64b |