Author: ramiro Date: 2011-11-07 03:28:31 -0800 (Mon, 07 Nov 2011) New Revision: 17077
Modified: django/trunk/django/core/management/base.py django/trunk/tests/modeltests/user_commands/tests.py Log: Fixed #11118 -- Made management command BaseCommand restore locale after execution. Thanks rvdrijst for the report and initial patch and Claude Paroz for enhancing it. Modified: django/trunk/django/core/management/base.py =================================================================== --- django/trunk/django/core/management/base.py 2011-11-07 07:41:24 UTC (rev 17076) +++ django/trunk/django/core/management/base.py 2011-11-07 11:28:31 UTC (rev 17077) @@ -203,9 +203,11 @@ # like permissions, and those shouldn't contain any translations. # But only do this if we can assume we have a working settings file, # because django.utils.translation requires settings. + saved_lang = None if self.can_import_settings: try: from django.utils import translation + saved_lang = translation.get_language() translation.activate('en-us') except ImportError, e: # If settings should be available, but aren't, @@ -232,6 +234,8 @@ except CommandError, e: self.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e))) sys.exit(1) + if saved_lang is not None: + translation.activate(saved_lang) def validate(self, app=None, display_num_errors=False): """ Modified: django/trunk/tests/modeltests/user_commands/tests.py =================================================================== --- django/trunk/tests/modeltests/user_commands/tests.py 2011-11-07 07:41:24 UTC (rev 17076) +++ django/trunk/tests/modeltests/user_commands/tests.py 2011-11-07 11:28:31 UTC (rev 17077) @@ -3,6 +3,7 @@ from django.core import management from django.core.management.base import CommandError from django.test import TestCase +from django.utils import translation class CommandTests(TestCase): @@ -18,5 +19,11 @@ self.assertEqual(out.getvalue(), "I don't feel like dancing Jive.") + def test_language_preserved(self): + out = StringIO() + with translation.override('fr'): + management.call_command('dance', stdout=out) + self.assertEqual(translation.get_language(), 'fr') + def test_explode(self): - self.assertRaises(CommandError, management.call_command, ('explode',)) \ No newline at end of file + self.assertRaises(CommandError, management.call_command, ('explode',)) -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.