Ticket #11118: 11118-2.diff

File 11118-2.diff, 2.1 KB (added by Claude Paroz, 12 years ago)

Simplify patch and add test

  • django/core/management/base.py

    diff --git a/django/core/management/base.py b/django/core/management/base.py
    index f1d8263..e728b90 100644
    a b class BaseCommand(object):  
    203203        # like permissions, and those shouldn't contain any translations.
    204204        # But only do this if we can assume we have a working settings file,
    205205        # because django.utils.translation requires settings.
     206        saved_lang = None
    206207        if self.can_import_settings:
    207208            try:
    208209                from django.utils import translation
     210                saved_lang = translation.get_language()
    209211                translation.activate('en-us')
    210212            except ImportError, e:
    211213                # If settings should be available, but aren't,
    class BaseCommand(object):  
    232234        except CommandError, e:
    233235            self.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
    234236            sys.exit(1)
     237        if saved_lang is not None:
     238            translation.activate(saved_lang)
    235239
    236240    def validate(self, app=None, display_num_errors=False):
    237241        """
  • tests/modeltests/user_commands/tests.py

    diff --git a/tests/modeltests/user_commands/tests.py b/tests/modeltests/user_commands/tests.py
    index bf74a98..896dd66 100644
    a b from StringIO import StringIO  
    33from django.core import management
    44from django.core.management.base import CommandError
    55from django.test import TestCase
     6from django.utils import translation
    67
    78
    89class CommandTests(TestCase):
    class CommandTests(TestCase):  
    1819        self.assertEqual(out.getvalue(),
    1920            "I don't feel like dancing Jive.")
    2021
     22    def test_language_preserved(self):
     23        out = StringIO()
     24        with translation.override('fr'):
     25            management.call_command('dance', stdout=out)
     26            self.assertEqual(translation.get_language(), 'fr')
     27
    2128    def test_explode(self):
    22         self.assertRaises(CommandError, management.call_command, ('explode',))
    23  No newline at end of file
     29        self.assertRaises(CommandError, management.call_command, ('explode',))
Back to Top