Skip to main content

Django-admin-commands

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

  1. Can execute management commands which is required to access & execute commands allowed.

  2. 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)

Metadata

Release files for django-admin-commands2 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-admin-commands2 1.1.3
File Size Uploaded Provenance
django-admin-commands2-1.1.3.tar.gz 10.8 kB Without provenance Details

Release files / django-admin-commands2-1.1.3.tar.gz

Download URL django-admin-commands2-1.1.3.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
41fcda45bb9b1a4031898f00724c2cc224e20af48389c9c3de3ef3dd0ec6221c
BLAKE2b-256 checksum
How to use checksums
be053c8b3d1de6ff44abaddf4d8e14044aa1d9f07a5d83fa5cd514c4f0710542
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for django-admin-commands2 1.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page