summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYitzhak Clark <yitz13@gmail.com>2015-04-13 13:27:14 -0400
committerTim Graham <timograham@gmail.com>2015-04-16 09:42:18 -0400
commit188a2418807f661eedfc675731521f2f46a3c49a (patch)
tree0efffa46168f9b01e6c1e8172e4ab68ead80bfd5
parent355c5edd9390caad5725375abca03460805f663b (diff)
downloaddjango-188a2418807f661eedfc675731521f2f46a3c49a.tar.gz
Fixed #21652 -- Added notification when processing objects in loaddata
Added a running count of the objects processed by loaddata when verbosity >= 3.
-rw-r--r--django/core/management/commands/loaddata.py9
-rw-r--r--tests/fixtures/tests.py10
2 files changed, 18 insertions, 1 deletions
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
index 464e19ce0c..32a676d846 100644
--- a/django/core/management/commands/loaddata.py
+++ b/django/core/management/commands/loaddata.py
@@ -122,6 +122,7 @@ class Command(BaseCommand):
"""
Loads fixtures files for a given label.
"""
+ show_progress = self.verbosity >= 3
for fixture_file, fixture_dir, fixture_name in self.find_fixtures(fixture_label):
_, ser_fmt, cmp_fmt = self.parse_name(os.path.basename(fixture_file))
open_method, mode = self.compression_formats[cmp_fmt]
@@ -144,6 +145,11 @@ class Command(BaseCommand):
self.models.add(obj.object.__class__)
try:
obj.save(using=self.using)
+ if show_progress:
+ self.stdout.write(
+ '\rProcessed %i object(s).' % loaded_objects_in_fixture,
+ ending=''
+ )
except (DatabaseError, IntegrityError) as e:
e.args = ("Could not load %(app_label)s.%(object_name)s(pk=%(pk)s): %(error_msg)s" % {
'app_label': obj.object._meta.app_label,
@@ -152,7 +158,8 @@ class Command(BaseCommand):
'error_msg': force_text(e)
},)
raise
-
+ if objects and show_progress:
+ self.stdout.write('') # add a newline after progress indicator
self.loaded_object_count += loaded_objects_in_fixture
self.fixture_object_count += objects_in_fixture
except Exception as e:
diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py
index f809c349f7..8eec3145b8 100644
--- a/tests/fixtures/tests.py
+++ b/tests/fixtures/tests.py
@@ -342,6 +342,16 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
'<Article: Who needs more than one database?>',
])
+ def test_loaddata_verbosity_three(self):
+ output = six.StringIO()
+ management.call_command('loaddata', 'fixture1.json', verbosity=3, stdout=output, stderr=output)
+ command_output = output.getvalue()
+ self.assertIn(
+ "\rProcessed 1 object(s).\rProcessed 2 object(s)."
+ "\rProcessed 3 object(s).\rProcessed 4 object(s).\n",
+ command_output
+ )
+
def test_loading_using(self):
# Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly
management.call_command('loaddata', 'db_fixture_1', verbosity=0, using='default')