Opened 17 years ago
Closed 17 years ago
#5222 closed (fixed)
Ability for end users to register commands with management.py.
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | management commands | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Changeset [5923] added the ability for end users to register commands with management.py. This was rolled out [5923]-[5925] due to breaking call_command().
I've patched init.py to allow users to register commands with management.py without breaking call_command.
A bit of a hack, but it works. Basically, I set a global dict _DJANGO_COMMANDS to hold all default commands and update itself with project specific commands when DJANGO_SETTINGS_MODULE is set.
call_command changes to:
def call_command(name, *args, **options): """ @@ -26,7 +69,7 @@ call_command('shell', plain=True) call_command('sqlall', 'myapp') """ - klass = load_command_class(name) + klass = getattr(__import__(_DJANGO_COMMANDS[name].__module__, {}, {}, ['Command']), 'Command')()
Attachments (4)
Change History (8)
by , 17 years ago
Attachment: | __init__.py.diff added |
---|
comment:1 by , 17 years ago
The last line was causing problems with runserver so I removed it and another unnecessary line.
This means that using this patch, project commands wont be available for and production server setup or any other time you manually specify DJANGO_SETTINGS_MODULE.
Hence, if you are calling project commands through any views, you should do management._DJANGO_COMMANDS.update(management.load_project_commands()).
by , 17 years ago
Attachment: | __init__.2.py added |
---|
The patched version of init.py with the last line removed.
by , 17 years ago
Attachment: | __init__.py.2.diff added |
---|
Diff file of init.py with last line removed.
comment:2 by , 17 years ago
Patch needs improvement: | set |
---|
comment:3 by , 17 years ago
Patch needs improvement: | unset |
---|
Diff file of init.py allowing end users to register management commands.