Visually distinguish environments in Django Admin

Overview

django-admin-env-notice

https://travis-ci.org/dizballanze/django-admin-env-notice.svg?branch=master

Visually distinguish environments in Django Admin. Based on great advice from post: 5 ways to make Django Admin safer by hakibenita.

Requirements

  • Python 2.7, 3.4+
  • Django 1.9+

Quickstart

Install django-admin-env-notice:

pip install django-admin-env-notice

Add it to your INSTALLED_APPS before django.contrib.admin:

INSTALLED_APPS = (
    ...
    'django_admin_env_notice',
    'django.contrib.admin',
    ...
)

Add context processor:

TEMPLATES = [
    {
        ...
        "OPTIONS": {
            "context_processors": [
                ...
                "django_admin_env_notice.context_processors.from_settings",
            ],
        },
    },
]

Set label and color for current environment:

ENVIRONMENT_NAME = "Production server"
ENVIRONMENT_COLOR = "#FF2222"

Override django admin selector if necessary (default: body), e.g: grappelli:

ENVIRONMENT_ADMIN_SELECTOR = "grp-header"

Optionally, set the environment banner to float over instead of being fixed to the top:

ENVIRONMENT_FLOAT = True

Screenshots

./screenshots/prod.png

./screenshots/dev.png

./screenshots/testing.png

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package:

Comments
  • Dont work

    Dont work

    • django-admin-env-notice version:
    • Django version: 2.1
    • Python version: 3.7
    • Operating System: Ubuntu 18.04

    Dont work, I follow all the settings and do not modify the admin template.

    Body:before is not work

    bug can't reproduce 
    opened by fjbardelli 10
  • Does this work with Django 4.0?

    Does this work with Django 4.0?

    • django-admin-env-notice version: 0.4.0
    • Django version: 4.0.1
    • Python version: 3.10.2
    • Operating System: Linux Mint

    Description

    Installed per instructions, set ENVIRONMENT_NAME, ENVIRONMENT_COLOR.

    Expected to see a RED banner with Production on the /admin after login.

    Got nothing.

    What I Did

    Paste the command(s) you ran and the output.
    If there was a crash, please include the traceback here.
    
    opened by lanshark 3
  • :rocket: added admin template selector override

    :rocket: added admin template selector override

    Basically we just need a setting to override the template selector so that when we have x,y,z admin theme setup we can hook it up however that theme works, in this case grappelli.

    opened by radyz 3
  • Compatibility using Django Grappelli

    Compatibility using Django Grappelli

    • django-admin-env-notice version: 0.1.1
    • Django version: 1.11.2
    • Python version: 3.6
    • Operating System: Linux

    Description

    I am trying to setup django admin env notice using django grappelli

    What I Did

    I installed the package and I got the following:

    Everything looks good image

    But when I scroll down I see a space in the top because the position of the header in grappelli is fixed image

    Would be great to have compatibility with grappelli. Regards.

    opened by Xepe 2
  • Incorrect syntax (closing condition)

    Incorrect syntax (closing condition)

    https://github.com/dizballanze/django-admin-env-notice/blob/0e46f41f93c07f23cad7a4a6a022e0f77f506278/django_admin_env_notice/templates/admin/base_site.html#L16

    Incorrect wrapping/closing. Lines 16 and 17 should be switched.

    opened by eriktelepovsky 1
  • Using in own templates

    Using in own templates

    • django-admin-env-notice version:
    • Django version:
    • Python version:
    • Operating System:

    Description

    I need for some parts of my application a custom management interface that cannot be done with the Django admin interface. Is there a way how I can show this notice in a "normal" template?

    opened by hendrikschneider 0
  • CSP support

    CSP support

    Putting unsafe-inline scripts is restricted via django-csp. You can try to reproduce this issue in this template: https://github.com/wemake-services/wemake-django-template

    127.0.0.1/:10 Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self' cdn.rawgit.com". Either the 'unsafe-inline' keyword, a hash ('sha256-QaA+rno7IxCZrUdNWEHh6+Xx4plAX/G3Py8TzgPyLJ0='), or a nonce ('nonce-...') is required to enable inline execution.

    What do I suggest? I suggest using nonce to fix it: https://django-csp.readthedocs.io/en/latest/nonce.html#context-processor

    So, this will only require that CSP context processors should come before yours.

    opened by sobolevn 0
  • In floating mode, banner eventually scrolls off screen

    In floating mode, banner eventually scrolls off screen

    • django-admin-env-notice version: 0.4
    • Django version: 4.0.6
    • Python version: 3.8.10
    • Operating System: windows/amazon linux

    Description

    Float mode works great except if you have longer pages...then it eventually scrolls off-screen as you scroll down the page.

    opened by dmwyatt 0
  • ⬆️ Bump wheel from 0.29.0 to 0.38.1

    ⬆️ Bump wheel from 0.29.0 to 0.38.1

    Bumps wheel from 0.29.0 to 0.38.1.

    Changelog

    Sourced from wheel's changelog.

    Release Notes

    UNRELEASED

    • Updated vendored packaging to 22.0

    0.38.4 (2022-11-09)

    • Fixed PKG-INFO conversion in bdist_wheel mangling UTF-8 header values in METADATA (PR by Anderson Bravalheri)

    0.38.3 (2022-11-08)

    • Fixed install failure when used with --no-binary, reported on Ubuntu 20.04, by removing setup_requires from setup.cfg

    0.38.2 (2022-11-05)

    • Fixed regression introduced in v0.38.1 which broke parsing of wheel file names with multiple platform tags

    0.38.1 (2022-11-04)

    • Removed install dependency on setuptools
    • The future-proof fix in 0.36.0 for converting PyPy's SOABI into a abi tag was faulty. Fixed so that future changes in the SOABI will not change the tag.

    0.38.0 (2022-10-21)

    • Dropped support for Python < 3.7
    • Updated vendored packaging to 21.3
    • Replaced all uses of distutils with setuptools
    • The handling of license_files (including glob patterns and default values) is now delegated to setuptools>=57.0.0 (#466). The package dependencies were updated to reflect this change.
    • Fixed potential DoS attack via the WHEEL_INFO_RE regular expression
    • Fixed ValueError: ZIP does not support timestamps before 1980 when using SOURCE_DATE_EPOCH=0 or when on-disk timestamps are earlier than 1980-01-01. Such timestamps are now changed to the minimum value before packaging.

    0.37.1 (2021-12-22)

    • Fixed wheel pack duplicating the WHEEL contents when the build number has changed (#415)
    • Fixed parsing of file names containing commas in RECORD (PR by Hood Chatham)

    0.37.0 (2021-08-09)

    • Added official Python 3.10 support
    • Updated vendored packaging library to v20.9

    ... (truncated)

    Commits
    • 6f1608d Created a new release
    • cf8f5ef Moved news item from PR #484 to its proper place
    • 9ec2016 Removed install dependency on setuptools (#483)
    • 747e1f6 Fixed PyPy SOABI parsing (#484)
    • 7627548 [pre-commit.ci] pre-commit autoupdate (#480)
    • 7b9e8e1 Test on Python 3.11 final
    • a04dfef Updated the pypi-publish action
    • 94bb62c Fixed docs not building due to code style changes
    • d635664 Updated the codecov action to the latest version
    • fcb94cd Updated version to match the release
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Do not show notice to users before auth

    Do not show notice to users before auth

    • django-admin-env-notice version: N/A
    • Django version: N/A
    • Python version: N/A
    • Operating System: N/A

    Description

    I'm wondering if you would be open to adding a new feature or accepting a PR along the following lines:

    On my sites, I like to put additional information in the env bar, such as the name of the git branch the site is on, the sha, and other information that ideally, I'd want to keep out of the public eye. It would be possible to modify the template to only show the bar if the user is_authorized, effectively limiting the data in the header to logged-in users. This feature would default to showing the bar, but could be enabled via an environment variable.

    What do you think?

    opened by avi-perl 1
  • [Enhancement] Noscript notice header above environment notice header

    [Enhancement] Noscript notice header above environment notice header

    It would be nice to have a separate header identical to the environment notice header, but above it, to let a user know when JavaScript is disabled (as some admin features seem to depend on JS).

    So if JavaScript is disabled, the new noscript header would just push the environment header down, and both would be sticky, if this is selected in settings.

    Disclosure: I have never tried this package with anything like Grappelli, but hopefully the additional header would not interfere with other packages such as that.

    opened by venteto 0
  • Not working with Grappelli 3.0.2 and Django 3.2.12

    Not working with Grappelli 3.0.2 and Django 3.2.12

    • django-admin-env-notice version: 0.4
    • Django version: 3.2.12
    • Python version: 3.10.2
    • Operating System: Manjaro

    Description

    Trying to get django-admin-env-notice to work with grappelli The bar is not showing on the admin site

    What I Did

    ENVIRONMENT_NAME = 'Local'
    
    ENVIRONMENT_COLOR = 'GREY'
    

    Tried the following selectors and also without any selectors:

    ENVIRONMENT_ADMIN_SELECTOR = "grp-header"
    ENVIRONMENT_ADMIN_SELECTOR = ".grp-module-login:before, #grp-header"
    
    ENVIRONMENT_FLOAT = True
    
    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR, 'templates/')],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django_admin_env_notice.context_processors.from_settings',
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                    'django.template.context_processors.request',
                ],
            },
        },
    ]
    

    django_admin_env_notice in INSTALLED_APPS above django.contrib.admin

    opened by shivam-sachit 0
Owner
Yuri Shikanov
Software developer
Yuri Shikanov
Jet Bridge (Universal) for Jet Admin – API-based Admin Panel Framework for your application

Jet Bridge for Jet Admin – Admin panel framework for your application Description About Jet Admin: https://about.jetadmin.io Live Demo: https://app.je

Jet Admin 1.3k Dec 27, 2022
aiohttp admin is generator for admin interface based on aiohttp

aiohttp admin is generator for admin interface based on aiohttp

Mykhailo Havelia 17 Nov 16, 2022
📱 An extension for Django admin that makes interface mobile-friendly. Merged into Django 2.0

Django Flat Responsive django-flat-responsive is included as part of Django from version 2.0! ?? Use this app if your project is powered by an older D

elky 248 Sep 2, 2022
An improved django-admin-tools dashboard for Django projects

django-fluent-dashboard The fluent_dashboard module offers a custom admin dashboard, built on top of django-admin-tools (docs). The django-admin-tools

django-fluent 326 Nov 9, 2022
A Django app for easily adding object tools in the Django admin

Django Object Actions If you've ever tried making admin object tools you may have thought, "why can't this be as easy as making Django Admin Actions?"

Chris Chang 524 Dec 26, 2022
Disable dark mode in Django admin user interface in Django 3.2.x.

Django Non Dark Admin Disable or enable dark mode user interface in Django admin panel (Django==3.2). Installation For install this app run in termina

Artem Galichkin 6 Nov 23, 2022
Modern responsive template for the Django admin interface with improved functionality. We are proud to announce completely new Jet. Please check out Live Demo

Django JET Modern template for Django admin interface with improved functionality Attention! NEW JET We are proud to announce completely new Jet. Plea

Geex Arts 3.4k Dec 29, 2022
Drop-in replacement of Django admin comes with lots of goodies, fully extensible with plugin support, pretty UI based on Twitter Bootstrap.

Xadmin Drop-in replacement of Django admin comes with lots of goodies, fully extensible with plugin support, pretty UI based on Twitter Bootstrap. Liv

差沙 4.7k Dec 31, 2022
A jazzy skin for the Django Admin-Interface (official repository).

Django Grappelli A jazzy skin for the Django admin interface. Grappelli is a grid-based alternative/extension to the Django administration interface.

Patrick Kranzlmueller 3.4k Dec 31, 2022
A Django admin theme using Twitter Bootstrap. It doesn't need any kind of modification on your side, just add it to the installed apps.

django-admin-bootstrapped A Django admin theme using Bootstrap. It doesn't need any kind of modification on your side, just add it to the installed ap

null 1.6k Dec 28, 2022
django's default admin interface made customizable. popup windows replaced by modals. :mage: :zap:

django-admin-interface django-admin-interface is a modern responsive flat admin interface customizable by the admin itself. Features Beautiful default

Fabio Caccamo 1.3k Dec 31, 2022
Extendable, adaptable rewrite of django.contrib.admin

django-admin2 One of the most useful parts of django.contrib.admin is the ability to configure various views that touch and alter data. django-admin2

Jazzband 1.2k Dec 29, 2022
Modern theme for Django admin interface

Django Suit Modern theme for Django admin interface. Django Suit is alternative theme/skin/extension for Django administration interface. Project home

Kaspars Sprogis 2.2k Dec 29, 2022
Django application and library for importing and exporting data with admin integration.

django-import-export django-import-export is a Django application and library for importing and exporting data with included admin integration. Featur

null 2.6k Jan 7, 2023
:honey_pot: A fake Django admin login screen page.

django-admin-honeypot django-admin-honeypot is a fake Django admin login screen to log and notify admins of attempted unauthorized access. This app wa

Derek Payton 907 Dec 31, 2022
"Log in as user" for the Django admin.

django-loginas About "Login as user" for the Django admin. loginas supports Python 3 only, as of version 0.4. If you're on 2, use 0.3.6. Installing dj

Stavros Korokithakis 326 Dec 3, 2022
A new style for Django admin

Djamin Djamin a new and clean styles for Django admin based in Google projects styles. Quick start Install djamin: pip install -e git://github.com/her

Herson Leite 236 Dec 15, 2022
Responsive Theme for Django Admin With Sidebar Menu

Responsive Django Admin If you're looking for a version compatible with Django 1.8 just install 0.3.7.1. Features Responsive Sidebar Menu Easy install

Douglas Miranda 852 Dec 2, 2022
A Django admin theme using Twitter Bootstrap. It doesn't need any kind of modification on your side, just add it to the installed apps.

django-admin-bootstrapped A Django admin theme using Bootstrap. It doesn't need any kind of modification on your side, just add it to the installed ap

null 1.6k Dec 28, 2022