Ticket #17980: 17980-signal.diff

File 17980-signal.diff, 2.8 KB (added by Claude Paroz, 13 years ago)

Use a signal to properly handle LANGUAGE_CODE change

  • django/contrib/auth/tests/views.py

    diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py
    index 7244086..cea7056 100644
    a b from django.contrib.auth.forms import (AuthenticationForm, PasswordChangeForm,  
    1919                SetPasswordForm, PasswordResetForm)
    2020
    2121
     22@override_settings(
     23    USE_TZ=False,
     24    LANGUAGES=(('en', 'English'),),
     25    LANGUAGE_CODE='en',
     26    TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
     27)
    2228class AuthViewsTestCase(TestCase):
    2329    """
    2430    Helper base class for all the follow test cases.
    class AuthViewsTestCase(TestCase):  
    2632    fixtures = ['authtestdata.json']
    2733    urls = 'django.contrib.auth.tests.urls'
    2834
    29     def setUp(self):
    30         self.old_LANGUAGES = settings.LANGUAGES
    31         self.old_LANGUAGE_CODE = settings.LANGUAGE_CODE
    32         settings.LANGUAGES = (('en', 'English'),)
    33         settings.LANGUAGE_CODE = 'en'
    34         self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
    35         settings.TEMPLATE_DIRS = (
    36             os.path.join(os.path.dirname(__file__), 'templates'),
    37         )
    38 
    39     def tearDown(self):
    40         settings.LANGUAGES = self.old_LANGUAGES
    41         settings.LANGUAGE_CODE = self.old_LANGUAGE_CODE
    42         settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
    43 
    4435    def login(self, password='password'):
    4536        response = self.client.post('/login/', {
    4637            'username': 'testclient',
    class AuthViewsTestCase(TestCase):  
    5344    def assertContainsEscaped(self, response, text, **kwargs):
    5445        return self.assertContains(response, escape(force_unicode(text)), **kwargs)
    5546
    56 AuthViewsTestCase = override_settings(USE_TZ=False)(AuthViewsTestCase)
    57 
    5847
    5948class AuthViewNamedURLTests(AuthViewsTestCase):
    6049    urls = 'django.contrib.auth.urls'
  • django/test/signals.py

    diff --git a/django/test/signals.py b/django/test/signals.py
    index 01d5581..08393f5 100644
    a b  
    11from django.conf import settings
    22from django.db import connections
    3 from django.dispatch import Signal
     3from django.dispatch import Signal, receiver
    44
    55template_rendered = Signal(providing_args=["template", "context"])
    66
    77setting_changed = Signal(providing_args=["setting", "value"])
    88
     9@receiver(setting_changed)
    910def update_connections_time_zone(**kwargs):
    1011    if kwargs['setting'] == 'USE_TZ' and settings.TIME_ZONE != 'UTC':
    1112        USE_TZ, TIME_ZONE = kwargs['value'], settings.TIME_ZONE
    def update_connections_time_zone(**kwargs):  
    2021        if tz_sql:
    2122            conn.cursor().execute(tz_sql, [tz])
    2223
    23 setting_changed.connect(update_connections_time_zone)
     24@receiver(setting_changed)
     25def change_default_language(**kwargs):
     26    if kwargs['setting'] == 'LANGUAGE_CODE':
     27        from django.utils.translation import trans_real
     28        trans_real._default = None
Back to Top