Commit a58a1200 authored by Tim Graham's avatar Tim Graham
Browse files

[1.8.x] Standardized indentation in docs/howto/custom-management-commands.txt.

parent bfa34788
Loading
Loading
Loading
Loading
+84 −87
Original line number Diff line number Diff line
@@ -69,13 +69,15 @@ look like this::

                self.stdout.write('Successfully closed poll "%s"' % poll_id)

.. versionchanged:: 1.8

    Before Django 1.8, management commands were based on the :py:mod:`optparse`
    module, and positional arguments were passed in ``*args`` while optional
    arguments were passed in ``**options``. Now that management commands use
    :py:mod:`argparse` for argument parsing, all arguments are passed in
``**options`` by default, unless you name your positional arguments to ``args``
(compatibility mode). You are encouraged to exclusively use ``**options`` for
new commands.
    ``**options`` by default, unless you name your positional arguments to
    ``args`` (compatibility mode). You are encouraged to exclusively use
    ``**options`` for new commands.

.. _management-commands-output:

@@ -266,16 +268,15 @@ All attributes can be set in your derived class and can be used in

    .. deprecated:: 1.8

      You should now override the :meth:`~BaseCommand.add_arguments` method to
      add custom arguments accepted by your command.
      See :ref:`the example above <custom-commands-options>`.
        You should now override the :meth:`~BaseCommand.add_arguments` method
        to add custom arguments accepted by your command. See :ref:`the example
        above <custom-commands-options>`.

.. attribute:: BaseCommand.output_transaction

  A boolean indicating whether the command outputs SQL
  statements; if ``True``, the output will automatically be
  wrapped with ``BEGIN;`` and ``COMMIT;``. Default value is
  ``False``.
    A boolean indicating whether the command outputs SQL statements; if
    ``True``, the output will automatically be wrapped with ``BEGIN;`` and
    ``COMMIT;``. Default value is ``False``.

.. attribute:: BaseCommand.requires_system_checks

@@ -294,10 +295,9 @@ All attributes can be set in your derived class and can be used in
    .. deprecated:: 1.7
        Replaced by ``requires_system_checks``

  A boolean; if ``True``, validation of installed models will be
  performed prior to executing the command. Default value is
  ``True``. To validate an individual application's models
  rather than all applications' models, call
    A boolean; if ``True``, validation of installed models will be performed
    prior to executing the command. Default value is ``True``. To validate an
    individual application's models rather than all applications' models, call
    :meth:`~BaseCommand.validate` from :meth:`~BaseCommand.handle`.

.. attribute:: BaseCommand.leave_locale_alone
@@ -309,15 +309,16 @@ All attributes can be set in your derived class and can be used in

    Make sure you know what you are doing if you decide to change the value of
    this option in your custom command if it creates database content that
  is locale-sensitive and such content shouldn't contain any translations (like
  it happens e.g. with django.contrib.auth permissions) as making the locale
  differ from the de facto default 'en-us' might cause unintended effects. See
  the `Management commands and locales`_ section above for further details.
    is locale-sensitive and such content shouldn't contain any translations
    (like it happens e.g. with django.contrib.auth permissions) as making the
    locale differ from the de facto default 'en-us' might cause unintended
    effects. Seethe `Management commands and locales`_ section above for
    further details.

    This option can't be ``False`` when the
    :data:`~BaseCommand.can_import_settings` option is set to ``False`` too
  because attempting to set the locale needs access to settings. This condition
  will generate a :class:`CommandError`.
    because attempting to set the locale needs access to settings. This
    condition will generate a :class:`CommandError`.

Methods
-------
@@ -422,17 +423,16 @@ each application.

.. class:: LabelCommand

A management command which takes one or more arbitrary arguments
(labels) on the command line, and does something with each of
them.
A management command which takes one or more arbitrary arguments (labels) on
the command line, and does something with each of them.

Rather than implementing :meth:`~BaseCommand.handle`, subclasses must implement
:meth:`~LabelCommand.handle_label`, which will be called once for each label.

.. method:: LabelCommand.handle_label(label, **options)

    Perform the command's actions for ``label``, which will be the
    string as given on the command line.
    Perform the command's actions for ``label``, which will be the string as
    given on the command line.

.. class:: NoArgsCommand

@@ -457,16 +457,13 @@ Command exceptions

.. class:: CommandError

Exception class indicating a problem while executing a management
command.
Exception class indicating a problem while executing a management command.

If this exception is raised during the execution of a management
command from a command line console, it will be caught and turned into a
nicely-printed error message to the appropriate output stream (i.e., stderr);
as a result, raising this exception (with a sensible description of the
error) is the preferred way to indicate that something has gone
wrong in the execution of a command.
If this exception is raised during the execution of a management command from a
command line console, it will be caught and turned into a nicely-printed error
message to the appropriate output stream (i.e., stderr); as a result, raising
this exception (with a sensible description of the error) is the preferred way
to indicate that something has gone wrong in the execution of a command.

If a management command is called from code through
:ref:`call_command <call-command>`, it's up to you to catch the exception
when needed.
If a management command is called from code through :ref:`call_command
<call-command>`, it's up to you to catch the exception when needed.