diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2007-09-21 16:19:20 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2007-09-21 16:19:20 +0000 |
| commit | 302eeaf1904a2f3852b223a563617d4999b4e9ae (patch) | |
| tree | 5d73317ee7b283fbd658d579ff8550a301d61c3d /tests | |
| parent | 2570954a9aa8ae8ad1edb6927f80b5952dfe5674 (diff) | |
Fixed #5516 -- Added the ability for applications to define their own management commands. Pieces of this patch taken from a contribution by Todd O'Bryan. Thanks Todd.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6400 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
5 files changed, 39 insertions, 0 deletions
diff --git a/tests/modeltests/user_commands/__init__.py b/tests/modeltests/user_commands/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/modeltests/user_commands/__init__.py diff --git a/tests/modeltests/user_commands/management/__init__.py b/tests/modeltests/user_commands/management/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/modeltests/user_commands/management/__init__.py diff --git a/tests/modeltests/user_commands/management/commands/__init__.py b/tests/modeltests/user_commands/management/commands/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/modeltests/user_commands/management/commands/__init__.py diff --git a/tests/modeltests/user_commands/management/commands/dance.py b/tests/modeltests/user_commands/management/commands/dance.py new file mode 100644 index 0000000000..5886cd1d8f --- /dev/null +++ b/tests/modeltests/user_commands/management/commands/dance.py @@ -0,0 +1,9 @@ +from django.core.management.base import BaseCommand + +class Command(BaseCommand): + help = "Dance around like a madman." + args = '' + requires_model_validation = True + + def handle(self, *args, **options): + print "I don't feel like dancing."
\ No newline at end of file diff --git a/tests/modeltests/user_commands/models.py b/tests/modeltests/user_commands/models.py new file mode 100644 index 0000000000..5f96806dac --- /dev/null +++ b/tests/modeltests/user_commands/models.py @@ -0,0 +1,30 @@ +""" +37. User-registered management commands + +The manage.py utility provides a number of useful commands for managing a +Django project. If you want to add a utility command of your own, you can. + +The user-defined command 'dance' is defined in the management/commands +subdirectory of this test application. It is a simple command that responds +with a printed message when invoked. + +For more details on how to define your own manage.py commands, look at the +django.core.management.commands directory. This directory contains the +definitions for the base Django manage.py commands. +""" + +__test__ = {'API_TESTS': """ +>>> from django.core import management + +# Invoke a simple user-defined command +>>> management.call_command('dance') +I don't feel like dancing. + +# Invoke a command that doesn't exist +>>> management.call_command('explode') +Traceback (most recent call last): +... +CommandError: Unknown command: 'explode' + + +"""}
\ No newline at end of file |
