Giter Site home page Giter Site logo

dizballanze / django-admin-env-notice Goto Github PK

View Code? Open in Web Editor NEW
308.0 14.0 20.0 222 KB

Visually distinguish environments in Django Admin

License: MIT License

Makefile 10.74% Python 83.90% HTML 5.36%
django django-admin django-admin-panel python

django-admin-env-notice's Introduction

django-admin-env-notice

Package Version Build Status Code Coverage

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

You can also set the text color (default: white) by setting:

ENVIRONMENT_TEXT_COLOR = "#00FF00"

You can stop showing the banner to unauthenticated users by setting (default: True):

ENVIRONMENT_SHOW_TO_UNAUTHENTICATED = False

Screenshots

Running Tests

Does the code actually work?

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

Credits

Tools used in rendering this package:

django-admin-env-notice's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-admin-env-notice's Issues

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?

[feature] text color

It would be cool to have a third variable for text color, so that using bright banners doesn't result in unreadable white-on-white.

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.

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.

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?

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

[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.

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

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.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.