Skip to main content

Plugin interface to list and execute existing management commands.

Project description

Django Commands UI

This project offers a solution to list and execute all existing management commands in your Django project.

Requirements

This project requires Python 3.10 or greater.

Configuration

To install and configure it these steps should be followed:

  1. Install the dependency from PyPi.

    pip install django-commands-ui
    
  2. Add commands_ui as an installed app in your Django project.

  3. If you haven't already done so, you will need to add celery to your django project. You can follow the steps in the First steps with Django guide if you haven't used celery before.

  4. Add the root location of your management commands to your installed apps. For example, if your management commands are in the commands folder in your project root, you would add your-project-name.commands to your installed apps.

  5. Add these required settings:

     # Celery app name.
     COMMANDS_UI_CELERY_APP = ""
    
     # Working celery queue name for delayed jobs.
     COMMANDS_UI_DELAYED_JOBS_QUEUE = ""
    
     # Working celery queue name for standard jobs.
     COMMANDS_UI_JOBS_QUEUE = ""
    
     # Tuple of compiled regexes to extract the runnable commands from.
     # By default, all commands from all installed apps are extracted.
     COMMANDS_UI_JOB_APPS = (re.compile(r".*"),)
    
     # Primary database identifyer, not the replica one.
     DATABASE_PRIMARY = getattr(settings, "DATABASE_PRIMARY", "default")
    
     # Define if the current environment is a cron environment.
     CRON_ENVIRONMENT = getattr(settings, "CRON_ENVIRONMENT", False)
    
  6. Include package URLs to your base urls file like this:

    path("jobs/", include("commands_ui.urls")),
    
  7. Create tables:

    python manage.py migrate commands_ui
    

It is recommended to override base.html so the appearance is customizable, as all django-commands-ui templates extend from it.

Documentation

Implementing a management command job

The only needed thing for implementing a working management command job in django-commands-ui is extending the existing JobBasedCommand. This class adds some default arguments (such as --job-id).

Example on how to use this class:

from typing import Any
from commands_ui import management_commands
from django.core.management.base import CommandParser

# Extend the JobBasedCommand class
class Command(management_commands.JobBasedCommand):
   def handle(self, *args: Any, **options: Any) -> None:
      # Any time `self.print` is used, the message will be added to both standard output and
      # Job output.
      self.print("Starting")
      for i in range(0, 20):
         self.print(i)
      self.print("Finishing")

Command Grouping

You can group types of commands by adding a interface_name class attribute to your management command class. This will group all commands with the same interface_name together in the UI. For example you can group cronjobs together by adding interface_name = "cron" to all your cronjobs.

from typing import Any
from commands_ui import management_commands
from django.core.management.base import CommandParser

# Extend the JobBasedCommand class
class Command(management_commands.JobBasedCommand):
    interface_name = "cron"
   def handle(self, *args: Any, **options: Any) -> None:
      ...

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_commands_ui-0.0.3.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

django_commands_ui-0.0.3-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file django_commands_ui-0.0.3.tar.gz.

File metadata

  • Download URL: django_commands_ui-0.0.3.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for django_commands_ui-0.0.3.tar.gz
Algorithm Hash digest
SHA256 892106c87629d4cac3835f96eba52ec47c44c8494c710a9283cea2d8f2ad7b83
MD5 c77d3cc95b03f05fdee633224d2e9e79
BLAKE2b-256 bcc0f0e6dc5f079834cd3c62b4da40efdef88afeaf36bbde1a88819d44b26899

See more details on using hashes here.

File details

Details for the file django_commands_ui-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_commands_ui-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c171123285b4bb46ed4a46a44e0da97371478518a2763ece9bf840880137ee3e
MD5 4db40cb4b0905e7b0e03463109724b87
BLAKE2b-256 bbe9f353b42d513e732efa4b9c75291da6a9aa00424a3f5cf171d168cc4c711b

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