Django

Code

Ticket #5222 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

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

Reported by: dnordberg@gmail.com Assigned to: adrian
Milestone: Component: Core framework
Version: SVN Keywords: management commands
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

__init__.py.diff (4.6 kB) - added by dnordberg@gmail.com on 08/21/07 03:27:47.
Diff file of init.py allowing end users to register management commands.
__init__.py (9.3 kB) - added by dnordberg@gmail.com on 08/21/07 03:41:52.
The patched version of init.py
__init__.2.py (7.7 kB) - added by dnordberg@gmail.com on 08/21/07 06:14:09.
The patched version of init.py with the last line removed.
__init__.py.2.diff (10.4 kB) - added by dnordberg@gmail.com on 08/21/07 06:15:16.
Diff file of init.py with last line removed.

Change History

08/21/07 03:27:47 changed by dnordberg@gmail.com

  • attachment __init__.py.diff added.

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

08/21/07 03:41:52 changed by dnordberg@gmail.com

  • attachment __init__.py added.

The patched version of init.py

08/21/07 06:11:20 changed by anonymous

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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()).

08/21/07 06:14:09 changed by dnordberg@gmail.com

  • attachment __init__.2.py added.

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

08/21/07 06:15:16 changed by dnordberg@gmail.com

  • attachment __init__.py.2.diff added.

Diff file of init.py with last line removed.

08/21/07 06:15:52 changed by anonymous

  • needs_better_patch set to 1.

08/21/07 15:52:41 changed by anonymous

  • needs_better_patch deleted.

09/04/07 07:59:49 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(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].


Add/Change #5222 (Ability for end users to register commands with management.py.)




Change Properties
Action