django-mcadmin is a Django reusable app that provides simple run management commands from admin
Installation
Obtain your copy of source code from the git repository: $ git clone https://github.com/vint21h/django-mcadmin.git. Or download the latest release from https://github.com/vint21h/django-mcadmin/tags/.
Run $ python ./setup.py install from the repository source tree or unpacked archive. Or use pip: $ pip install django-mcadmin.
Configuration
Add "mcadmin" to settings.INSTALLED_APPS:
# settings.py
INSTALLED_APPS += [
"mcadmin",
]
Add "mcadmin" to your URLs definitions:
# urls.py
from django.urls import re_path, include
urlpatterns += [
re_path(r"^admin/mcadmin/", include("mcadmin.urls")),
]
Run $ python ./manage.py migrate in your project folder to apply app migrations.
Settings
- MCADMIN_EXAMPLES_PATH
Management commands files templates path. Defaults to: settings.STATIC_ROOT.
- MCADMIN_UPLOADS_PATH
Management commands forms with files upload path. Defaults to: settings.MEDIA_ROOT.
- MCADMIN_MODULE_NAME
Management commands admin classes search module name. Defaults to: "mcommands".
- MCADMIN_USE_PERMISSIONS
Management commands admin classes search module name. Defaults to: False.
Usage
For example, exists management command like this:
# management/commands/something-useless.py
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help: str = "Useless management command"
def add_arguments(self, parser):
parser.add_argument(
"--object-id",
"-o",
dest="object_id",
help="Object ID",
action="store",
required=True,
metavar="OBJECT_ID",
type=int,
)
def handle(self, *args, **kwargs):
self.stdout.write(kwargs.get("object_id"))
Next, you need to create a form for this management command admin which we use in the next piece of code:
# forms.py
from django import forms
class SomethingUselessManagementCommandAdminForm(forms.Form):
object_id = forms.IntegerField(label="Object ID", required=True)
And finally, write management command admin class and register it:
# mcommands/something-useless.py
from mcadmin.command import ManagementCommandAdmin
from mcadmin.registry import registry
from forms import SomethingUselessManagementCommandAdminForm
class SomethingUselessManagementCommandAdmin(ManagementCommandAdmin):
command: str = "something-useless"
name: str = "Useless management command"
form: Type[Form] = SomethingUselessManagementCommandAdminForm
# registering management command admin custom classes
registry.register(command=SomethingUselessManagementCommandAdmin)
Also, there are some helpers for building more complex flows, like management commands that can be executed directly or as a background task or management commands that handle uploaded files. For example:
Management command:
# management/commands/distributed-something-useless-with-file.py
from mcadmin.management.commands import TaskCommand
class Command(TaskCommand):
help: str = "Useless management command which process file uploaded from a command from and can be executed directly or as background task"
def add_arguments(self, parser):
parser.add_argument(
"--task",
"-T",
dest="as_task",
help="Run command as background task",
default=False,
action="store",
metavar="TASK",
type=bool,
)
parser.add_argument(
"--object-id",
"-o",
dest="object_id",
help="Object ID",
action="store",
required=True,
metavar="OBJECT_ID",
type=int,
)
parser.add_argument(
"--data",
"-D",
dest="data",
help="Path to file with data",
action="store",
metavar="DATA",
type=str,
)
def _local(self, *args, **kwargs):
self.stdout.write(kwargs.get("object_id"))
self.stdout.write(kwargs.get("data"))
def _as_task(self, *args, **kwargs):
# There must be code which executed in threads or call celery task or something else asynchronous.
self.stdout.write(kwargs.get("object_id"))
self.stdout.write(kwargs.get("data"))
Management command admin form:
# forms.py
from django import forms
from mcadmin.forms.helpers import (
ManagementCommandAdminTaskForm,
ManagementCommandAdminFilesForm
)
class DistributedSomethingUselessWithFileManagementCommandAdminForm(
ManagementCommandAdminTaskForm,
ManagementCommandAdminFilesForm
):
data = forms.FileField(label="data, required=True)
object_id = forms.IntegerField(label="Object ID", required=True)
Management command admin example file:
# mcommands/examples.py
from mcadmin.example import ManagementCommandAdminExampleFile
class DistributedSomethingUselessWithFileManagementCommandAdminExampleFile(
ManagementCommandAdminExampleFile
):
description: str = "Management command with files example file"
path: str = "distributed-something-useless-with-file-example.csv"
Or for the file which not served using Django but directly available for download via HTTP:
# mcommands/examples.py
from mcadmin.example import ManagementCommandAdminExampleFile
class DistributedSomethingUselessWithFileManagementCommandAdminExampleFile(
ManagementCommandAdminExampleFile
):
description: str = "Management command with files example file"
path: str = "https://www.example.com/distributed-something-useless-with-file-example.csv"
raw: bool = True
Management command admin:
# mcommands/something-useless.py
from mcadmin.command import ManagementCommandAdmin
from mcadmin.registry import registry
from forms import DistributedSomethingUselessWithFileManagementCommandAdminForm
class DistributedSomethingUselessWithFileManagementCommandAdmin(ManagementCommandAdmin):
command: str = "distributed-something-useless-with-file"
name: str = "Distributed useless management command with file"
form: Type[Form] = DistributedSomethingUselessWithFileManagementCommandAdminForm
examples: Type[ManagementCommandAdminExampleFile] = [DistributedSomethingUselessWithFileManagementCommandAdminExampleFile]
# registering management command admin custom classes
registry.register(command=DistributedSomethingUselessWithFileManagementCommandAdmin)
Contributing
Install GNU Make
Install and configure pyenv and pyenv-virtualenv plugin
Install and configure direnv
Create environment config from example
cp .env.example .env
Install development dependencies:
make install
Create your fix/feature branch:
git checkout -b my-new-fix-or-feature
Check code style and moreover:
make check
Run tests:
make test
Push to the branch:
git push origin my-new-fix-or-feature
Licensing
django-mcadmin is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. For complete license text see COPYING file.
Contacts
Project Website: https://github.com/vint21h/django-mcadmin/
Author: Alexei Andrushievich <vint21h@vint21h.pp.ua>
For other authors list see AUTHORS file.
Metadata
Release files for django-mcadmin 0.12.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-mcadmin-0.12.0.zip | 60.0 kB | Without provenance | Details for django-mcadmin-0.12.0.zip |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_mcadmin-0.12.0-py3-none-any.whl | Python 3 | none | any | Details for django_mcadmin-0.12.0-py3-none-any.whl |
Total release size: 105.8 kB
Release files / django-mcadmin-0.12.0.zip
| Download URL | django-mcadmin-0.12.0.zip |
|---|---|
| Size | 60.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09091a76bf58b69cd1d3c7d0bbfe476a960aa5e4b6146ab8f6a131e6d55da4a2
|
|
BLAKE2b-256 checksum How to use checksums |
a77f7d38bd22d07856609b071395393a52f0fcfbcee4385fb913dada2a71dffe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Release files / django_mcadmin-0.12.0-py3-none-any.whl
| Download URL | django_mcadmin-0.12.0-py3-none-any.whl |
|---|---|
| Size | 45.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3a36e33b96d0da45f0abdafda74fe04f77afecbd13a9e0a3613332182cc51f5d
|
|
BLAKE2b-256 checksum How to use checksums |
122fae15bac787df8ebdeb76aa55bf2d042ee06d4de9868832e72f0514bf272d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
|
Security for django-mcadmin 0.12.0
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.