Ticket #1480: t1480-r9690.diff

File t1480-r9690.diff, 5.2 KB (added by ramiro, 7 years ago)
  • django/conf/__init__.py

    diff -r f04277ed359f django/conf/__init__.py
    a b  
    119119                new_installed_apps.append(app)
    120120        self.INSTALLED_APPS = new_installed_apps
    121121
    122         if hasattr(time, 'tzset'):
     122        if hasattr(time, 'tzset') and hasattr(self, 'TIME_ZONE') and bool(self.TIME_ZONE):
    123123            # Move the time zone info into os.environ. See ticket #2315 for why
    124124            # we don't do this unconditionally (breaks Windows).
    125125            os.environ['TZ'] = self.TIME_ZONE
  • django/conf/project_template/settings.py

    diff -r f04277ed359f django/conf/project_template/settings.py
    a b  
    1919# Local time zone for this installation. Choices can be found here:
    2020# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
    2121# 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.
    2224# If running in a Windows environment this must be set to the same as your
    2325# system time zone.
    2426TIME_ZONE = 'America/Chicago'
  • django/db/backends/postgresql/base.py

    diff -r f04277ed359f django/db/backends/postgresql/base.py
    a b  
    9696        self.validation = BaseDatabaseValidation()
    9797
    9898    def _cursor(self, settings):
     99        new_conn = False
    99100        set_tz = False
    100101        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)
    102104            if settings.DATABASE_NAME == '':
    103105                from django.core.exceptions import ImproperlyConfigured
    104106                raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
     
    114116            self.connection = Database.connect(conn_string, **self.options)
    115117            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
    116118        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])
    119122            if not hasattr(self, '_version'):
    120123                self.__class__._version = get_version(cursor)
    121124            if self._version < (8, 0):
  • django/db/backends/postgresql_psycopg2/base.py

    diff -r f04277ed359f django/db/backends/postgresql_psycopg2/base.py
    a b  
    6666        self.validation = BaseDatabaseValidation()
    6767
    6868    def _cursor(self, settings):
     69        new_conn = False
    6970        set_tz = False
    7071        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)
    7274            if settings.DATABASE_NAME == '':
    7375                from django.core.exceptions import ImproperlyConfigured
    7476                raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
     
    8688            self.connection.set_client_encoding('UTF8')
    8789        cursor = self.connection.cursor()
    8890        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])
    9194            if not hasattr(self, '_version'):
    9295                self.__class__._version = get_version(cursor)
    9396            if self._version < (8, 0):
  • docs/ref/settings.txt

    diff -r f04277ed359f docs/ref/settings.txt
    a b  
    11551155
    11561156Normally, Django sets the ``os.environ['TZ']`` variable to the time zone you
    11571157specify 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.
     1158automatically operate in the correct time zone. However, in the following two
     1159scenarios:
     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
     1165Django will *not* touch the ``TZ`` environment variable, and it'll be up to you
     1166to ensure your processes are running in the correct environment.
     1167
     1168.. versionadded:: 1.1
     1169
     1170This setting can also be set to ``None`` for deployment scenarios in which you
     1171need the timezone to remain in the server's timezone.
    11631172
    11641173.. note::
    11651174    Django cannot reliably use alternate time zones in a Windows environment.
Back to Top