Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added option to pretty-print dumped fixture output

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4661 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 790b5858194d66f3fe1c2bb8d266408469049166 1 parent a72f908
@freakboy3742 freakboy3742 authored
Showing with 19 additions and 4 deletions.
  1. +5 −3 django/core/management.py
  2. +14 −1 docs/django-admin.txt
View
8 django/core/management.py
@@ -1413,7 +1413,7 @@ def load_data(fixture_labels, verbosity=1):
load_data.help_doc = 'Installs the named fixture(s) in the database'
load_data.args = "[--verbosity] fixture, fixture, ..."
-def dump_data(app_labels, format='json'):
+def dump_data(app_labels, format='json', indent=None):
"Output the current contents of the database as a fixture of the given format"
from django.db.models import get_app, get_apps, get_models
from django.core import serializers
@@ -1435,7 +1435,7 @@ def dump_data(app_labels, format='json'):
for model in get_models(app):
objects.extend(model.objects.all())
try:
- print serializers.serialize(format, objects)
+ print serializers.serialize(format, objects, indent=indent)
except Exception, e:
sys.stderr.write(style.ERROR("Unable to serialize database: %s\n" % e))
dump_data.help_doc = 'Output the contents of the database as a fixture of the given format'
@@ -1525,6 +1525,8 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
help='Tells Django to NOT use the auto-reloader when running the development server.')
parser.add_option('--format', default='json', dest='format',
help='Specifies the output serialization format for fixtures')
+ parser.add_option('--indent', default=None, dest='indent',
+ type='int', help='Specifies the indent level to use when pretty-printing output')
parser.add_option('--verbosity', action='store', dest='verbosity', default='1',
type='choice', choices=['0', '1', '2'],
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
@@ -1579,7 +1581,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
parser.print_usage_and_exit()
elif action == 'dumpdata':
try:
- action_mapping[action](args[1:], options.format)
+ action_mapping[action](args[1:], options.format, options.indent)
except IndexError:
parser.print_usage_and_exit()
elif action in ('startapp', 'startproject'):
View
15 docs/django-admin.txt
@@ -473,7 +473,7 @@ setting the Python path for you.
.. _import search path: http://diveintopython.org/getting_to_know_python/everything_is_an_object.html
--format
----------
+--------
**New in Django development version**
@@ -490,6 +490,19 @@ of a registered serializer.
Displays a help message that includes a terse list of all available actions and
options.
+--indent
+--------
+
+**New in Django development version**
+
+Example usage::
+
+ django-admin.py dumpdata --indent=4
+
+Specifies the number of spaces that will be used for indentation when
+pretty-printing output. By default, output will *not* be pretty-printed.
+Pretty-printing will only be enabled if the indent option is provided.
+
--noinput
---------
Please sign in to comment.
Something went wrong with that request. Please try again.