Code

Ticket #19749: 19749-2.diff

File 19749-2.diff, 1.7 KB (added by claudep, 17 months ago)

Mention the ending parameter

Line 
1diff --git a/docs/howto/custom-management-commands.txt b/docs/howto/custom-management-commands.txt
2index bfcea64..7a31fc4 100644
3--- a/docs/howto/custom-management-commands.txt
4+++ b/docs/howto/custom-management-commands.txt
5@@ -65,12 +65,18 @@ look like this:
6 
7                 self.stdout.write('Successfully closed poll "%s"' % poll_id)
8 
9+.. _management-commands-output:
10+
11 .. note::
12     When you are using management commands and wish to provide console
13     output, you should write to ``self.stdout`` and ``self.stderr``,
14     instead of printing to ``stdout`` and ``stderr`` directly. By
15     using these proxies, it becomes much easier to test your custom
16-    command.
17+    command. Note also that you don't need to end messages with a newline
18+    character, it will be added automatically, unless you specify the ``ending``
19+    parameter::
20+
21+        self.stdout.write("Unterminated line", ending='')
22 
23 The new custom command can be called using ``python manage.py closepoll
24 <poll_id>``.
25diff --git a/docs/releases/1.5.txt b/docs/releases/1.5.txt
26index a5ce08a..03e4855 100644
27--- a/docs/releases/1.5.txt
28+++ b/docs/releases/1.5.txt
29@@ -253,6 +253,11 @@ Django 1.5 also includes several smaller improvements worth noting:
30   from :ref:`call_command <call-command>`. Any exception raised by the command
31   (mostly :ref:`CommandError <ref-command-exceptions>`) is propagated.
32 
33+  Moreover, when you output errors or messages in your custom commands, you
34+  should now use ``self.stdout.write('message')`` and
35+  ``self.stderr.write('error')`` (see the note on
36+  :ref:`management commands output <management-commands-output>`).
37+
38 * The dumpdata management command outputs one row at a time, preventing
39   out-of-memory errors when dumping large datasets.
40