diff --git a/django/test/signals.py b/django/test/signals.py
index 052b7df..d27f8d7 100644
a
|
b
|
import os
|
2 | 2 | import time |
3 | 3 | |
4 | 4 | from django.conf import settings |
5 | | from django.db import connections |
6 | 5 | from django.dispatch import receiver, Signal |
7 | 6 | from django.template import context |
8 | 7 | from django.utils import timezone |
… |
… |
setting_changed = Signal(providing_args=["setting", "value"])
|
16 | 15 | |
17 | 16 | |
18 | 17 | @receiver(setting_changed) |
19 | | def update_connections_time_zone(**kwargs): |
20 | | if kwargs['setting'] == 'TIME_ZONE': |
| 18 | def update_connections_time_zone(sender, setting, value): |
| 19 | if setting not in ('USE_TZ', 'TIME_ZONE'): |
| 20 | return |
| 21 | if setting == 'TIME_ZONE': |
21 | 22 | # Reset process time zone |
22 | 23 | if hasattr(time, 'tzset'): |
23 | | if kwargs['value']: |
24 | | os.environ['TZ'] = kwargs['value'] |
| 24 | if value: |
| 25 | os.environ['TZ'] = value |
25 | 26 | else: |
26 | 27 | os.environ.pop('TZ', None) |
27 | 28 | time.tzset() |
… |
… |
def update_connections_time_zone(**kwargs):
|
29 | 30 | # Reset local time zone cache |
30 | 31 | timezone._localtime = None |
31 | 32 | |
| 33 | try: |
| 34 | from django.db import connections |
| 35 | except ImproperlyConfigured: |
| 36 | # No databases setup, quit |
| 37 | return |
| 38 | |
32 | 39 | # 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 |
37 | 44 | else: |
38 | 45 | # no need to change the database connnections' time zones |
39 | 46 | return |