Execute management commands via admin with ease and control.
Project description
Because sometimes you want to give teh admin access to some commands. This app allows you to specify the commands you want to allow the admin to execute. It also logs the commands executed and the output of the command.
Features
Specify the commands you need to allow for admin to execute. (Or explicitly choose all)
Get the logs, stdout, stderr in admin.
Easy permissions
Easily customizable to use django-rq or other queueing technique
Installation
Install directly from repo
pip install git+https://github.com/KUWAITNET/django-admin-commands#egg=django-admin-commands2
Install from pypi
Use the package manager pip to install django-admin-commands2. There is a package with the same name on pypi , hence the 2 suffix
pip install django-admin-commands2
Add admin_commands to your INSTALLED_APPS
python manage.py migrate
Usage
Adds the commands you need to allow to the admin to your settings. Example:
# settings.py
ADMIN_COMMANDS_CONFIG = {
'allowed_commands': [
'ping_google', # command name
('update_index', '--no-input') # you can also pass arguments to the command,
]
# You can also use the following to allow all commands
# 'allowed_commands': 'all'
'use_django_rq': True, # If you want to use django-rq to execute the commands, default is False
}
Navigate to the admin site and you will see a new section called Management Commands with commands to execute and see their logs
Permissions
App comes with 2 permissions
Can execute management commands which is required to access & execute commands allowed.
View other users log which is allow the user to see the logs of other users ran commands. If Not given, logs will be filtered to own records only.
Customization
You can override the admin class for ManagementCommandsAdmin to customize the admin view.
# admin.py
from admin_commands.admin import CommandAdminBase, ManagementCommandAdmin
from admin_commands.models import ManagementCommands
class CustomManagementCommandsAdmin(ManagementCommandAdmin):
def execute_command_and_return_response(self, request, command, args):
# Easy Entry point to customize execution,
import django_rq
django_rq.enqueue(command.execute, request.user, args)
# OR without django_rq
command.execute(request.user, args)
self.message_user(request, _('Command executed'))
return self.response_post_save_add(request, command)
def execute_command_view(self, request, object_id):
# This is the view that is called when the user clicks on the execute button, you can override this to
# customize the execution of the command, check source for information on how to do this.
return super().execute_command_view(request, object_id)
def get_queryset(self, request):
# This is the queryset that is used to filter the commands that are shown in the admin.
# You can override this to customize the queryset for the user
return super().get_queryset(request)
admin.site.unregister(ManagementCommands)
admin.site.register(ManagementCommands, CustomManagementCommandsAdmin)
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
File details
Details for the file django-admin-commands2-1.1.3.tar.gz
.
File metadata
- Download URL: django-admin-commands2-1.1.3.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41fcda45bb9b1a4031898f00724c2cc224e20af48389c9c3de3ef3dd0ec6221c |
|
MD5 | 6ba561abc7a9cf206828ff28f1c478e3 |
|
BLAKE2b-256 | be053c8b3d1de6ff44abaddf4d8e14044aa1d9f07a5d83fa5cd514c4f0710542 |