Skip to main content

A public read-only version of the Django Admin

Project description

Django Public Admin

A public and read-only version of the Django Admin. A drop-in replacement for Django's native AdminSite and ModelAdmin for publicly accessible data.

How does it work

  1. PublicAdminSite works as a clone of Django's native AdminSite, but it looks at the HTTP request and the URL to decide whether they should exist in a public and read-only dashboard.
  2. PublicModelAdmin work as a clone of Django's native ModelAdmin, but what it does is to stop actions that would create, edit or delete objects.
  3. DummyUser is just a an implementation detail, since Django requires an user to process the requests.

Install

As this package is not finished nor published, this command does not work just yet. However, Poetry should install it in the local virtualenv one can access with poetry shell.

$ pip install django-public-admin

Usage

1. Create your Django Public Admin instance

Just like one would create a regular admin.py, you can create a module using Django Public Admin's PublicAdminSite and PublicModelAdmin:

from public_admin.admin import PublicModelAdmin
from public_admin.sites import PublicAdminSite, PublicApp

from my_website.my_open_house.models import Beverage, Snack


class BeverageModelAdmin(PublicModelAdmin):
    pass


class SnackModelAdmin(PublicModelAdmin):
    pass


public_app = PublicApp("my_open_house", models=("beverage", "snack"))
public_admin = PublicAdminSite(
    "dashboard",  # you name it as you wish
    public_app,  # this can be a single public app or a sequence of public apps
)
public_admin.register(Beverage, BeverageModelAdmin)
public_admin.register(Sanck, SanckModelAdmin)

2. Add your Django Public Admin URLs

In your urls.py, import the public_html (or whatever you've named it earlier) in your URLs file and create the endpoints:

from django.urls import path

from my_website.my_open_house.admin import public_admin


url = [
    # …
    path("dashboard/", public_admin.urls)
]

3. Templates

Django Public Admin comes with a template that hides from the UI elements related to user, login and logout. To use it, add public_admin to your INSTALLED_APPS before django.contrib.admin:

INSTALLED_APPS = [
    "public_admin",
    "django.contrib.admin",
    # ...
]

If you decide not to use it, you have to create your own templates/base.html to avoid errors when rendering the template. Django will fail, for example, in rendering URLs that do not exist, which would be the case for login and logout.

Contributing

We use tox to Run tests with Python 3.6, 3.7 and 3.8, and with Django 2 and 3. Also we use Black and flake8:

$ poetry install
$ poetry run tox

License & Credits

This package is licensed under MIT license and acknowledge Serenata de AmorOpen Knowledge Brasil and, previously, © Data Science Brigade).

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-public-admin-0.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

django_public_admin-0.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file django-public-admin-0.0.1.tar.gz.

File metadata

  • Download URL: django-public-admin-0.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/4.19.0-8-amd64

File hashes

Hashes for django-public-admin-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2abdb3ef3044abb989c51f018b5fcacac9fee8a2de2e867cc12da940d98b20ac
MD5 dcfdcfe4d2cca8ea1a93b47846af2771
BLAKE2b-256 2464da818ab1a1bbebf1cb5c93824663d1ebbf188cd5edbf4dd43b7b4068bff0

See more details on using hashes here.

File details

Details for the file django_public_admin-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_public_admin-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 42a225e73589d582b336c26d9f7fb85efac62120e0969ca2179a55997c13ca93
MD5 3cb58f7e30703a1288ba5ab264ddb097
BLAKE2b-256 4e7931560765b0e3d756a66fda0862cb9d2e26817d868f48c05858ce94d0c997

See more details on using hashes here.

Supported by

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