Code

Ticket #1480: t1480-r9690.diff

File t1480-r9690.diff, 5.2 KB (added by ramiro, 5 years ago)
Line 
1diff -r f04277ed359f django/conf/__init__.py
2--- a/django/conf/__init__.py   Fri Dec 26 22:01:11 2008 -0200
3+++ b/django/conf/__init__.py   Wed Dec 31 16:50:57 2008 -0200
4@@ -119,7 +119,7 @@
5                 new_installed_apps.append(app)
6         self.INSTALLED_APPS = new_installed_apps
7 
8-        if hasattr(time, 'tzset'):
9+        if hasattr(time, 'tzset') and hasattr(self, 'TIME_ZONE') and bool(self.TIME_ZONE):
10             # Move the time zone info into os.environ. See ticket #2315 for why
11             # we don't do this unconditionally (breaks Windows).
12             os.environ['TZ'] = self.TIME_ZONE
13diff -r f04277ed359f django/conf/project_template/settings.py
14--- a/django/conf/project_template/settings.py  Fri Dec 26 22:01:11 2008 -0200
15+++ b/django/conf/project_template/settings.py  Wed Dec 31 16:50:57 2008 -0200
16@@ -19,6 +19,8 @@
17 # Local time zone for this installation. Choices can be found here:
18 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
19 # although not all choices may be available on all operating systems.
20+# On Unix systems you can set it to None if you want the timezone to remain
21+# equal to the server's timezone.
22 # If running in a Windows environment this must be set to the same as your
23 # system time zone.
24 TIME_ZONE = 'America/Chicago'
25diff -r f04277ed359f django/db/backends/postgresql/base.py
26--- a/django/db/backends/postgresql/base.py     Fri Dec 26 22:01:11 2008 -0200
27+++ b/django/db/backends/postgresql/base.py     Wed Dec 31 16:50:57 2008 -0200
28@@ -96,9 +96,11 @@
29         self.validation = BaseDatabaseValidation()
30 
31     def _cursor(self, settings):
32+        new_conn = False
33         set_tz = False
34         if self.connection is None:
35-            set_tz = True
36+            new_conn = True
37+            set_tz = hasattr(settings, 'TIME_ZONE') and bool(settings.TIME_ZONE)
38             if settings.DATABASE_NAME == '':
39                 from django.core.exceptions import ImproperlyConfigured
40                 raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
41@@ -114,8 +116,9 @@
42             self.connection = Database.connect(conn_string, **self.options)
43             self.connection.set_isolation_level(1) # make transactions transparent to all cursors
44         cursor = self.connection.cursor()
45-        if set_tz:
46-            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
47+        if new_conn:
48+            if set_tz:
49+                cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
50             if not hasattr(self, '_version'):
51                 self.__class__._version = get_version(cursor)
52             if self._version < (8, 0):
53diff -r f04277ed359f django/db/backends/postgresql_psycopg2/base.py
54--- a/django/db/backends/postgresql_psycopg2/base.py    Fri Dec 26 22:01:11 2008 -0200
55+++ b/django/db/backends/postgresql_psycopg2/base.py    Wed Dec 31 16:50:57 2008 -0200
56@@ -66,9 +66,11 @@
57         self.validation = BaseDatabaseValidation()
58 
59     def _cursor(self, settings):
60+        new_conn = False
61         set_tz = False
62         if self.connection is None:
63-            set_tz = True
64+            new_conn = True
65+            set_tz = hasattr(settings, 'TIME_ZONE') and bool(settings.TIME_ZONE)
66             if settings.DATABASE_NAME == '':
67                 from django.core.exceptions import ImproperlyConfigured
68                 raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
69@@ -86,8 +88,9 @@
70             self.connection.set_client_encoding('UTF8')
71         cursor = self.connection.cursor()
72         cursor.tzinfo_factory = None
73-        if set_tz:
74-            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
75+        if new_conn:
76+            if set_tz:
77+                cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
78             if not hasattr(self, '_version'):
79                 self.__class__._version = get_version(cursor)
80             if self._version < (8, 0):
81diff -r f04277ed359f docs/ref/settings.txt
82--- a/docs/ref/settings.txt     Fri Dec 26 22:01:11 2008 -0200
83+++ b/docs/ref/settings.txt     Wed Dec 31 16:50:57 2008 -0200
84@@ -1155,11 +1155,20 @@
85 
86 Normally, Django sets the ``os.environ['TZ']`` variable to the time zone you
87 specify in the ``TIME_ZONE`` setting. Thus, all your views and models will
88-automatically operate in the correct time zone. However, if you're manually
89-:ref:`manually configuring settings
90-<settings-without-django-settings-module>`, Django will *not* touch the ``TZ``
91-environment variable, and it'll be up to you to ensure your processes are
92-running in the correct environment.
93+automatically operate in the correct time zone. However, in the following two
94+scenarios:
95+
96+* If you set the ``TIME_ZONE`` setting to ``None``, as described below
97+* If you're using the manual configuration option as described in
98+  :ref:`settings-without-django-settings-module`
99+
100+Django will *not* touch the ``TZ`` environment variable, and it'll be up to you
101+to ensure your processes are running in the correct environment.
102+
103+.. versionadded:: 1.1
104+
105+This setting can also be set to ``None`` for deployment scenarios in which you
106+need the timezone to remain in the server's timezone.
107 
108 .. note::
109     Django cannot reliably use alternate time zones in a Windows environment.