Opened 17 years ago

Closed 17 years ago

#5222 closed (fixed)

Ability for end users to register commands with management.py.

Reported by: dnordberg@… 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)

__init__.py.diff (4.6 KB ) - added by dnordberg@… 17 years ago.
Diff file of init.py allowing end users to register management commands.
__init__.py (9.3 KB ) - added by dnordberg@… 17 years ago.
The patched version of init.py
__init__.2.py (7.7 KB ) - added by dnordberg@… 17 years ago.
The patched version of init.py with the last line removed.
__init__.py.2.diff (10.4 KB ) - added by dnordberg@… 17 years ago.
Diff file of init.py with last line removed.

Download all attachments as: .zip

Change History (8)

by dnordberg@…, 17 years ago

Attachment: __init__.py.diff added

Diff file of init.py allowing end users to register management commands.

by dnordberg@…, 17 years ago

Attachment: __init__.py added

The patched version of init.py

comment:1 by anonymous, 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 dnordberg@…, 17 years ago

Attachment: __init__.2.py added

The patched version of init.py with the last line removed.

by dnordberg@…, 17 years ago

Attachment: __init__.py.2.diff added

Diff file of init.py with last line removed.

comment:2 by anonymous, 17 years ago

Patch needs improvement: set

comment:3 by anonymous, 17 years ago

Patch needs improvement: unset

comment:4 by Russell Keith-Magee, 17 years ago

Resolution: fixed
Status: newclosed

(In [6047]) Fixed #5212, #5222 -- Added the ability for users to register their own commands with django-admin. A previous attempt at this was introduced in [5923]-[5925], and rolled out in [5929].

Note: See TracTickets for help on using tickets.
Back to Top