Expose Django management commands in the admin
Project description
django-managerie
:lightbulb: Expose Django management commands as forms in the admin, like so:
Requirements
- Django 4.2+ (this project tracks Django's end-of-life policy)
- Python 3.10+
Installation
Install the package as you would any Python package, then add django_managerie
to your INSTALLED_APPS
.
Automatic patching
This is the easiest way to get up and running. You can have Managerie patch the admin site's dashboard view to include pseudo-models with the name "Commands" for all apps where management commands are available, and while it's at it, it'll also include URLs of its own.
Hook up Managerie to your admin site (e.g. in urls.py
, where you have admin.autodiscover()
), like so:
from django.contrib import admin
from django_managerie import Managerie
# ...
managerie = Managerie(admin_site=admin.site)
managerie.patch()
No patching
This is likely safer (in the presence of slightly less tolerant 3rd party apps that mangle the admin, for instance), but you can't enjoy the luxury of the Commands buttons in the admin dashboard.
from django.contrib import admin
from django.conf.urls import include, url
from django_managerie import Managerie
# ...
managerie = Managerie(admin_site=admin.site)
# ...
urlpatterns = [
# ...
# ... url(r'^admin/', include(admin.site.urls)), ...
url(r'^admin/', include(managerie.urls)), # Add this!
]
Usage
If you allowed Managerie to patch your admin, superusers can now see Commands
"objects" in the admin dashboard.
If you didn't patch the admin, you can access a list of all commands through /admin/managerie/
(or wherever your admin is mounted).
If you click through to a command, you'll see the arguments of the command laid out as a form. Fill the form, then hit "Execute Command", and you're done! :sparkles:
Accessing the Django request from a managerie'd command
Managerie sets _managerie_request
on the command instance to the current Django request.
You can use it to access the request, for instance, to get the current user.
Accessing standard input
By default, Managerie will patch sys.stdin
to be an empty stream.
If you need to read from standard input (e.g. long input),
set the managerie_accepts_stdin
attribute on your command class to True
.
This will cause Managerie to add a text-area to the form, which will be passed to the command as standard input.
Note that sys.stdin.buffer
(binary mode) is not supported.
TODO
- More
argparse
action support - Multiple-argument support (
nargs
)
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
File details
Details for the file django_managerie-0.6.1.tar.gz
.
File metadata
- Download URL: django_managerie-0.6.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
daf90f3a3bc766bc80ef948ff271cd4eba8ac6c855b2e5a01239bc5cf2346fa5
|
|
MD5 |
5123ef2d1dde6f851d1930a626f3d088
|
|
BLAKE2b-256 |
3a915bba36eddd1d31062cd1adb36a1d4188042303e448b8952a0ac2f7553984
|
Provenance
The following attestation bundles were made for django_managerie-0.6.1.tar.gz
:
Publisher:
ci.yml
on akx/django-managerie
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
django_managerie-0.6.1.tar.gz
-
Subject digest:
daf90f3a3bc766bc80ef948ff271cd4eba8ac6c855b2e5a01239bc5cf2346fa5
- Sigstore transparency entry: 177355541
- Sigstore integration time:
-
Permalink:
akx/django-managerie@b1684c8e72242592f141b3b6adf09c25d7367f14
-
Branch / Tag:
refs/tags/v0.6.1
- Owner: https://github.com/akx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
ci.yml@b1684c8e72242592f141b3b6adf09c25d7367f14
-
Trigger Event:
push
-
Statement type:
File details
Details for the file django_managerie-0.6.1-py3-none-any.whl
.
File metadata
- Download URL: django_managerie-0.6.1-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
1af527e42c8a9c30f9c54203656c57682829468d68373d324d4484da068bf310
|
|
MD5 |
80f5bb59f4183ad96e346363397bbfd5
|
|
BLAKE2b-256 |
51c0576fa849050fbfbd09f65bec493f16181f271e1caf14214ee4b7a33e7e38
|
Provenance
The following attestation bundles were made for django_managerie-0.6.1-py3-none-any.whl
:
Publisher:
ci.yml
on akx/django-managerie
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
django_managerie-0.6.1-py3-none-any.whl
-
Subject digest:
1af527e42c8a9c30f9c54203656c57682829468d68373d324d4484da068bf310
- Sigstore transparency entry: 177355544
- Sigstore integration time:
-
Permalink:
akx/django-managerie@b1684c8e72242592f141b3b6adf09c25d7367f14
-
Branch / Tag:
refs/tags/v0.6.1
- Owner: https://github.com/akx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
ci.yml@b1684c8e72242592f141b3b6adf09c25d7367f14
-
Trigger Event:
push
-
Statement type: