Ticket #18575: 18575-1.diff

File 18575-1.diff, 1.9 KB (added by Claude Paroz, 12 years ago)

Late import of django.db.connections

  • django/test/signals.py

    diff --git a/django/test/signals.py b/django/test/signals.py
    index 052b7df..d27f8d7 100644
    a b import os  
    22import time
    33
    44from django.conf import settings
    5 from django.db import connections
    65from django.dispatch import receiver, Signal
    76from django.template import context
    87from django.utils import timezone
    setting_changed = Signal(providing_args=["setting", "value"])  
    1615
    1716
    1817@receiver(setting_changed)
    19 def update_connections_time_zone(**kwargs):
    20     if kwargs['setting'] == 'TIME_ZONE':
     18def update_connections_time_zone(sender, setting, value):
     19    if setting not in ('USE_TZ', 'TIME_ZONE'):
     20        return
     21    if setting == 'TIME_ZONE':
    2122        # Reset process time zone
    2223        if hasattr(time, 'tzset'):
    23             if kwargs['value']:
    24                 os.environ['TZ'] = kwargs['value']
     24            if value:
     25                os.environ['TZ'] = value
    2526            else:
    2627                os.environ.pop('TZ', None)
    2728            time.tzset()
    def update_connections_time_zone(**kwargs):  
    2930        # Reset local time zone cache
    3031        timezone._localtime = None
    3132
     33    try:
     34        from django.db import connections
     35    except ImproperlyConfigured:
     36        # No databases setup, quit
     37        return
     38
    3239    # Reset the database connections' time zone
    33     if kwargs['setting'] == 'USE_TZ' and settings.TIME_ZONE != 'UTC':
    34         USE_TZ, TIME_ZONE = kwargs['value'], settings.TIME_ZONE
    35     elif kwargs['setting'] == 'TIME_ZONE' and not settings.USE_TZ:
    36         USE_TZ, TIME_ZONE = settings.USE_TZ, kwargs['value']
     40    if setting == 'USE_TZ' and settings.TIME_ZONE != 'UTC':
     41        USE_TZ, TIME_ZONE = value, settings.TIME_ZONE
     42    elif setting == 'TIME_ZONE' and not settings.USE_TZ:
     43        USE_TZ, TIME_ZONE = settings.USE_TZ, value
    3744    else:
    3845        # no need to change the database connnections' time zones
    3946        return
Back to Top