2012-03-13 14:59:04 +08:00
|
|
|
from django.conf import settings
|
2012-03-14 07:29:15 +08:00
|
|
|
from django.db import connections
|
2008-08-06 23:32:46 +08:00
|
|
|
from django.dispatch import Signal
|
|
|
|
|
|
|
|
template_rendered = Signal(providing_args=["template", "context"])
|
2011-05-18 20:08:53 +08:00
|
|
|
|
|
|
|
setting_changed = Signal(providing_args=["setting", "value"])
|
2012-03-13 14:59:04 +08:00
|
|
|
|
2012-03-14 07:29:15 +08:00
|
|
|
def update_connections_time_zone(**kwargs):
|
|
|
|
if kwargs['setting'] == 'USE_TZ' and settings.TIME_ZONE != 'UTC':
|
|
|
|
USE_TZ, TIME_ZONE = kwargs['value'], settings.TIME_ZONE
|
|
|
|
elif kwargs['setting'] == 'TIME_ZONE' and not settings.USE_TZ:
|
|
|
|
USE_TZ, TIME_ZONE = settings.USE_TZ, kwargs['value']
|
|
|
|
else: # no need to change the database connnections' time zones
|
|
|
|
return
|
|
|
|
|
|
|
|
tz = 'UTC' if USE_TZ else TIME_ZONE
|
|
|
|
for conn in connections.all():
|
|
|
|
tz_sql = conn.ops.set_time_zone_sql()
|
|
|
|
if tz_sql:
|
|
|
|
conn.cursor().execute(tz_sql, [tz])
|
|
|
|
|
|
|
|
setting_changed.connect(update_connections_time_zone)
|