PageRenderTime 26ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 1ms

/bangkokhotel/lib/python2.5/site-packages/django/test/signals.py

https://bitbucket.org/luisrodriguez/bangkokhotel
Python | 23 lines | 18 code | 5 blank | 0 comment | 9 complexity | 411c902e1ce6970900aadc8dee439f77 MD5 | raw file
 1from django.conf import settings
 2from django.db import connections
 3from django.dispatch import Signal
 4
 5template_rendered = Signal(providing_args=["template", "context"])
 6
 7setting_changed = Signal(providing_args=["setting", "value"])
 8
 9def update_connections_time_zone(**kwargs):
10    if kwargs['setting'] == 'USE_TZ' and settings.TIME_ZONE != 'UTC':
11        USE_TZ, TIME_ZONE = kwargs['value'], settings.TIME_ZONE
12    elif kwargs['setting'] == 'TIME_ZONE' and not settings.USE_TZ:
13        USE_TZ, TIME_ZONE = settings.USE_TZ, kwargs['value']
14    else:   # no need to change the database connnections' time zones
15        return
16
17    tz = 'UTC' if USE_TZ else TIME_ZONE
18    for conn in connections.all():
19        tz_sql = conn.ops.set_time_zone_sql()
20        if tz_sql:
21            conn.cursor().execute(tz_sql, [tz])
22
23setting_changed.connect(update_connections_time_zone)