From 9afc51bbcb28f89a621553176af191f5db548732 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 13 Mar 2007 00:29:21 +0000 Subject: [PATCH] Modified the internal dumpdata implementation to return the dumped data, rather than just printing to screen. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4715 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/management.py | 4 ++-- tests/modeltests/fixtures/models.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/django/core/management.py b/django/core/management.py index 21d867f2c5..25fb73d8ce 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -1436,7 +1436,7 @@ def dump_data(app_labels, format='json', indent=None): for model in get_models(app): objects.extend(model.objects.all()) try: - print serializers.serialize(format, objects, indent=indent) + return 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' @@ -1582,7 +1582,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, options.indent) + print action_mapping[action](args[1:], options.format, options.indent) except IndexError: parser.print_usage_and_exit() elif action in ('startapp', 'startproject'): diff --git a/tests/modeltests/fixtures/models.py b/tests/modeltests/fixtures/models.py index d82886a6c4..50714b7b04 100644 --- a/tests/modeltests/fixtures/models.py +++ b/tests/modeltests/fixtures/models.py @@ -73,7 +73,7 @@ Multiple fixtures named 'fixture2' in '.../fixtures'. Aborting. [, , ] # Dump the current contents of the database as a JSON fixture ->>> management.dump_data(['fixtures'], format='json') +>>> print management.dump_data(['fixtures'], format='json') [{"pk": "3", "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": "2", "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": "1", "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}] """}