Package: django-mcadmin
django-mcadmin is a Django reusable app that provides simple run management commands from adminContentsInstallationConfigurationSettingsUsageContributingLicensingContactsInstallationObtain your copy of source code from the git repository:$ git clonehttps://github.com/vint21h/django-mcadmin.git. Or download the latest release fromhttps://github.com/vint21h/django-mcadmin/tags/.Run$ python ./setup.py installfrom the repository source tree or unpacked archive. Or use pip:$ pip installdjango-mcadmin.ConfigurationAdd"mcadmin"tosettings.INSTALLED_APPS:# settings.pyINSTALLED_APPS+=["mcadmin",]Add"mcadmin"to your URLs definitions:# urls.pyfromdjango.urlsimportre_path,includeurlpatterns+=[re_path(r"^admin/mcadmin/",include("mcadmin.urls")),]Run$ python ./manage.py migratein your project folder to apply app migrations.SettingsMCADMIN_EXAMPLES_PATHManagement commands files templates path. Defaults to:settings.STATIC_ROOT.MCADMIN_UPLOADS_PATHManagement commands forms with files upload path. Defaults to:settings.MEDIA_ROOT.MCADMIN_MODULE_NAMEManagement commands admin classes search module name. Defaults to:"mcommands".MCADMIN_USE_PERMISSIONSManagement commands admin classes search module name. Defaults to:False.UsageFor example, exists management command like this:# management/commands/something-useless.pyfromdjango.core.management.baseimportBaseCommandclassCommand(BaseCommand):help:str="Useless management command"defadd_arguments(self,parser):parser.add_argument("--object-id","-o",dest="object_id",help="Object ID",action="store",required=True,metavar="OBJECT_ID",type=int,)defhandle(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.pyfromdjangoimportformsclassSomethingUselessManagementCommandAdminForm(forms.Form):object_id=forms.IntegerField(label="Object ID",required=True)And finally, write management command admin class and register it:# mcommands/something-useless.pyfrommcadmin.commandimportManagementCommandAdminfrommcadmin.registryimportregistryfromformsimportSomethingUselessManagementCommandAdminFormclassSomethingUselessManagementCommandAdmin(ManagementCommandAdmin):command:str="something-useless"name:str="Useless management command"form:Type[Form]=SomethingUselessManagementCommandAdminForm# registering management command admin custom classesregistry.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.pyfrommcadmin.management.commandsimportTaskCommandclassCommand(TaskCommand):help:str="Useless management command which process file uploaded from a command from and can be executed directly or as background task"defadd_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.pyfromdjangoimportformsfrommcadmin.forms.helpersimport(ManagementCommandAdminTaskForm,ManagementCommandAdminFilesForm)classDistributedSomethingUselessWithFileManagementCommandAdminForm(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.pyfrommcadmin.exampleimportManagementCommandAdminExampleFileclassDistributedSomethingUselessWithFileManagementCommandAdminExampleFile(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.pyfrommcadmin.exampleimportManagementCommandAdminExampleFileclassDistributedSomethingUselessWithFileManagementCommandAdminExampleFile(ManagementCommandAdminExampleFile):description:str="Management command with files example file"path:str="https://www.example.com/distributed-something-useless-with-file-example.csv"raw:bool=TrueManagement command admin:# mcommands/something-useless.pyfrommcadmin.commandimportManagementCommandAdminfrommcadmin.registryimportregistryfromformsimportDistributedSomethingUselessWithFileManagementCommandAdminFormclassDistributedSomethingUselessWithFileManagementCommandAdmin(ManagementCommandAdmin):command:str="distributed-something-useless-with-file"name:str="Distributed useless management command with file"form:Type[Form]=DistributedSomethingUselessWithFileManagementCommandAdminFormexamples:Type[ManagementCommandAdminExampleFile]=[DistributedSomethingUselessWithFileManagementCommandAdminExampleFile]# registering management command admin custom classesregistry.register(command=DistributedSomethingUselessWithFileManagementCommandAdmin)ContributingFork itInstallGNU MakeInstall and configurepyenvandpyenv-virtualenv pluginInstall and configuredirenvCreate environment config from examplecp.env.example.envInstall development dependencies:makeinstallCreate your fix/feature branch:gitcheckout-bmy-new-fix-or-featureCheck code style and moreover:makecheckRun tests:maketestPush to the branch:gitpushoriginmy-new-fix-or-featureCreate a new Pull RequestLicensingdjango-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.ContactsProject Website:https://github.com/vint21h/django-mcadmin/Author: Alexei Andrushievich <vint21h@vint21h.pp.ua>For other authors list see AUTHORS file.