diff -r f04277ed359f django/conf/__init__.py
|
a
|
b
|
|
| 119 | 119 | new_installed_apps.append(app) |
| 120 | 120 | self.INSTALLED_APPS = new_installed_apps |
| 121 | 121 | |
| 122 | | if hasattr(time, 'tzset'): |
| | 122 | if hasattr(time, 'tzset') and hasattr(self, 'TIME_ZONE') and bool(self.TIME_ZONE): |
| 123 | 123 | # Move the time zone info into os.environ. See ticket #2315 for why |
| 124 | 124 | # we don't do this unconditionally (breaks Windows). |
| 125 | 125 | os.environ['TZ'] = self.TIME_ZONE |
diff -r f04277ed359f django/conf/project_template/settings.py
|
a
|
b
|
|
| 19 | 19 | # Local time zone for this installation. Choices can be found here: |
| 20 | 20 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name |
| 21 | 21 | # although not all choices may be available on all operating systems. |
| | 22 | # On Unix systems you can set it to None if you want the timezone to remain |
| | 23 | # equal to the server's timezone. |
| 22 | 24 | # If running in a Windows environment this must be set to the same as your |
| 23 | 25 | # system time zone. |
| 24 | 26 | TIME_ZONE = 'America/Chicago' |
diff -r f04277ed359f django/db/backends/postgresql/base.py
|
a
|
b
|
|
| 96 | 96 | self.validation = BaseDatabaseValidation() |
| 97 | 97 | |
| 98 | 98 | def _cursor(self, settings): |
| | 99 | new_conn = False |
| 99 | 100 | set_tz = False |
| 100 | 101 | if self.connection is None: |
| 101 | | set_tz = True |
| | 102 | new_conn = True |
| | 103 | set_tz = hasattr(settings, 'TIME_ZONE') and bool(settings.TIME_ZONE) |
| 102 | 104 | if settings.DATABASE_NAME == '': |
| 103 | 105 | from django.core.exceptions import ImproperlyConfigured |
| 104 | 106 | raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.") |
| … |
… |
|
| 114 | 116 | self.connection = Database.connect(conn_string, **self.options) |
| 115 | 117 | self.connection.set_isolation_level(1) # make transactions transparent to all cursors |
| 116 | 118 | cursor = self.connection.cursor() |
| 117 | | if set_tz: |
| 118 | | cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) |
| | 119 | if new_conn: |
| | 120 | if set_tz: |
| | 121 | cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) |
| 119 | 122 | if not hasattr(self, '_version'): |
| 120 | 123 | self.__class__._version = get_version(cursor) |
| 121 | 124 | if self._version < (8, 0): |
diff -r f04277ed359f django/db/backends/postgresql_psycopg2/base.py
|
a
|
b
|
|
| 66 | 66 | self.validation = BaseDatabaseValidation() |
| 67 | 67 | |
| 68 | 68 | def _cursor(self, settings): |
| | 69 | new_conn = False |
| 69 | 70 | set_tz = False |
| 70 | 71 | if self.connection is None: |
| 71 | | set_tz = True |
| | 72 | new_conn = True |
| | 73 | set_tz = hasattr(settings, 'TIME_ZONE') and bool(settings.TIME_ZONE) |
| 72 | 74 | if settings.DATABASE_NAME == '': |
| 73 | 75 | from django.core.exceptions import ImproperlyConfigured |
| 74 | 76 | raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.") |
| … |
… |
|
| 86 | 88 | self.connection.set_client_encoding('UTF8') |
| 87 | 89 | cursor = self.connection.cursor() |
| 88 | 90 | cursor.tzinfo_factory = None |
| 89 | | if set_tz: |
| 90 | | cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) |
| | 91 | if new_conn: |
| | 92 | if set_tz: |
| | 93 | cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) |
| 91 | 94 | if not hasattr(self, '_version'): |
| 92 | 95 | self.__class__._version = get_version(cursor) |
| 93 | 96 | if self._version < (8, 0): |
diff -r f04277ed359f docs/ref/settings.txt
|
a
|
b
|
|
| 1155 | 1155 | |
| 1156 | 1156 | Normally, Django sets the ``os.environ['TZ']`` variable to the time zone you |
| 1157 | 1157 | specify in the ``TIME_ZONE`` setting. Thus, all your views and models will |
| 1158 | | automatically operate in the correct time zone. However, if you're manually |
| 1159 | | :ref:`manually configuring settings |
| 1160 | | <settings-without-django-settings-module>`, Django will *not* touch the ``TZ`` |
| 1161 | | environment variable, and it'll be up to you to ensure your processes are |
| 1162 | | running in the correct environment. |
| | 1158 | automatically operate in the correct time zone. However, in the following two |
| | 1159 | scenarios: |
| | 1160 | |
| | 1161 | * If you set the ``TIME_ZONE`` setting to ``None``, as described below |
| | 1162 | * If you're using the manual configuration option as described in |
| | 1163 | :ref:`settings-without-django-settings-module` |
| | 1164 | |
| | 1165 | Django will *not* touch the ``TZ`` environment variable, and it'll be up to you |
| | 1166 | to ensure your processes are running in the correct environment. |
| | 1167 | |
| | 1168 | .. versionadded:: 1.1 |
| | 1169 | |
| | 1170 | This setting can also be set to ``None`` for deployment scenarios in which you |
| | 1171 | need the timezone to remain in the server's timezone. |
| 1163 | 1172 | |
| 1164 | 1173 | .. note:: |
| 1165 | 1174 | Django cannot reliably use alternate time zones in a Windows environment. |