Browse files

Added option to pretty-print dumped fixture output

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent a72f908 commit 790b5858194d66f3fe1c2bb8d266408469049166 @freakboy3742 freakboy3742 committed Mar 2, 2007
Showing with 19 additions and 4 deletions.
  1. +5 −3 django/core/
  2. +14 −1 docs/django-admin.txt
8 django/core/
@@ -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):
- 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):
elif action == 'dumpdata':
- action_mapping[action](args[1:], options.format)
+ action_mapping[action](args[1:], options.format, options.indent)
except IndexError:
elif action in ('startapp', 'startproject'):
15 docs/django-admin.txt
@@ -473,7 +473,7 @@ setting the Python path for you.
.. _import search path:
**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
+**New in Django development version**
+Example usage::
+ 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.

0 comments on commit 790b585

Please sign in to comment.