Ticket #17882: 17882-second-take.patch
File 17882-second-take.patch, 4.1 KB (added by , 13 years ago) |
---|
-
django/test/signals.py
1 1 from django.conf import settings 2 from django.db import c lose_connection2 from django.db import connections 3 3 from django.dispatch import Signal 4 4 5 5 template_rendered = Signal(providing_args=["template", "context"]) 6 6 7 7 setting_changed = Signal(providing_args=["setting", "value"]) 8 8 9 # Close the database connection to re-establish it with the proper time zone. 10 def close_connection_on_time_zone_change(**kwargs): 11 if (kwargs['setting'] == 'USE_TZ' 12 or (kwargs['setting'] == 'TIME_ZONE' and not settings.USE_TZ)): 13 close_connection() 14 setting_changed.connect(close_connection_on_time_zone_change) 9 def 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 tz = 'UTC' if USE_TZ else TIME_ZONE 17 for conn in connections.all(): 18 tz_sql = conn.ops.set_time_zone_sql() 19 if tz_sql: 20 conn.cursor().execute(tz_sql, [tz]) 21 setting_changed.connect(update_connections_time_zone) -
django/db/backends/oracle/base.py
274 274 def savepoint_rollback_sql(self, sid): 275 275 return convert_unicode("ROLLBACK TO SAVEPOINT " + self.quote_name(sid)) 276 276 277 def set_time_zone_sql(self): 278 return "ALTER SESSION SET TIME_ZONE = %s" 279 277 280 def sql_flush(self, style, tables, sequences): 278 281 # Return a list of 'TRUNCATE x;', 'TRUNCATE y;', 279 282 # 'TRUNCATE z;'... style SQL statements -
django/db/backends/__init__.py
710 710 """ 711 711 raise NotImplementedError 712 712 713 def set_time_zone_sql(self): 714 """ 715 Returns the SQL that will set the connection's time zone. 716 717 Returns '' if the backend doesn't support time zones. 718 """ 719 return '' 720 713 721 def sql_flush(self, style, tables, sequences): 714 722 """ 715 723 Returns a list of SQL statements required to remove all data from -
django/db/backends/postgresql_psycopg2/base.py
190 190 # Set the time zone in autocommit mode (see #17062) 191 191 self.connection.set_isolation_level( 192 192 psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) 193 self.connection.cursor().execute("SET TIME ZONE %s", [tz]) 193 self.connection.cursor().execute( 194 self.ops.set_time_zone_sql(), [tz]) 194 195 self.connection.set_isolation_level(self.isolation_level) 195 196 self._get_pg_version() 196 197 connection_created.send(sender=self.__class__, connection=self) -
django/db/backends/postgresql_psycopg2/operations.py
71 71 return name # Quoting once is enough. 72 72 return '"%s"' % name 73 73 74 def set_time_zone_sql(self): 75 return "SET TIME ZONE %s" 76 74 77 def sql_flush(self, style, tables, sequences): 75 78 if tables: 76 79 # Perform a single SQL 'TRUNCATE x, y, z...;' statement. It allows