Python django.utils.timezone.get_current_timezone_name() Examples
The following are 30
code examples of django.utils.timezone.get_current_timezone_name().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.utils.timezone
, or try the search function
.
Example #1
Source File: edit_handlers.py From ls.joyous with BSD 3-Clause "New" or "Revised" License | 6 votes |
def on_instance_bound(self): super().on_instance_bound() if not self.form: # wait for the form to be set, it will eventually be return if not self.instance.overrides: return widget = self.form[self.field_name].field.widget widget.overrides_repeat = self.instance.overrides_repeat tz = timezone._get_timezone_name(self.instance.tz) if tz != timezone.get_current_timezone_name(): self.exceptionTZ = tz else: self.exceptionTZ = None # ------------------------------------------------------------------------------
Example #2
Source File: datetime.py From python2017 with MIT License | 5 votes |
def get_tzname(self): # Timezone conversions must happen to the input datetime *before* # applying a function. 2015-12-31 23:00:00 -02:00 is stored in the # database as 2016-01-01 01:00:00 +00:00. Any results should be # based on the input datetime not the stored datetime. tzname = None if settings.USE_TZ: if self.tzinfo is None: tzname = timezone.get_current_timezone_name() else: tzname = timezone._get_timezone_name(self.tzinfo) return tzname
Example #3
Source File: datetime.py From python with Apache License 2.0 | 5 votes |
def as_sql(self, compiler, connection): # Cast to date rather than truncate to date. lhs, lhs_params = compiler.compile(self.lhs) tzname = timezone.get_current_timezone_name() if settings.USE_TZ else None sql, tz_params = connection.ops.datetime_cast_date_sql(lhs, tzname) lhs_params.extend(tz_params) return sql, lhs_params
Example #4
Source File: datetime.py From python with Apache License 2.0 | 5 votes |
def as_sql(self, compiler, connection): # Cast to date rather than truncate to date. lhs, lhs_params = compiler.compile(self.lhs) tzname = timezone.get_current_timezone_name() if settings.USE_TZ else None sql, tz_params = connection.ops.datetime_cast_time_sql(lhs, tzname) lhs_params.extend(tz_params) return sql, lhs_params
Example #5
Source File: tz.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def render(self, context): context[self.variable] = timezone.get_current_timezone_name() return ''
Example #6
Source File: cache.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def _i18n_cache_key_suffix(request, cache_key): """If necessary, adds the current locale or time zone to the cache key.""" if settings.USE_I18N or settings.USE_L10N: # first check if LocaleMiddleware or another middleware added # LANGUAGE_CODE to request, then fall back to the active language # which in turn can also fall back to settings.LANGUAGE_CODE cache_key += '.%s' % getattr(request, 'LANGUAGE_CODE', get_language()) if settings.USE_TZ: # The datetime module doesn't restrict the output of tzname(). # Windows is known to use non-standard, locale-dependant names. # User-defined tzinfo classes may return absolutely anything. # Hence this paranoid conversion to create a valid cache key. tz_name = force_text(get_current_timezone_name(), errors='ignore') cache_key += '.%s' % tz_name.encode('ascii', 'ignore').decode('ascii').replace(' ', '_') return cache_key
Example #7
Source File: context_processors.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def tz(request): from django.utils import timezone return {'TIME_ZONE': timezone.get_current_timezone_name()}
Example #8
Source File: tz.py From openhgsenti with Apache License 2.0 | 5 votes |
def render(self, context): context[self.variable] = timezone.get_current_timezone_name() return ''
Example #9
Source File: cache.py From openhgsenti with Apache License 2.0 | 5 votes |
def _i18n_cache_key_suffix(request, cache_key): """If necessary, adds the current locale or time zone to the cache key.""" if settings.USE_I18N or settings.USE_L10N: # first check if LocaleMiddleware or another middleware added # LANGUAGE_CODE to request, then fall back to the active language # which in turn can also fall back to settings.LANGUAGE_CODE cache_key += '.%s' % getattr(request, 'LANGUAGE_CODE', get_language()) if settings.USE_TZ: # The datetime module doesn't restrict the output of tzname(). # Windows is known to use non-standard, locale-dependent names. # User-defined tzinfo classes may return absolutely anything. # Hence this paranoid conversion to create a valid cache key. tz_name = force_text(get_current_timezone_name(), errors='ignore') cache_key += '.%s' % tz_name.encode('ascii', 'ignore').decode('ascii').replace(' ', '_') return cache_key
Example #10
Source File: lookups.py From openhgsenti with Apache License 2.0 | 5 votes |
def as_sql(self, compiler, connection): lhs, lhs_params = compiler.compile(self.lhs) tzname = timezone.get_current_timezone_name() if settings.USE_TZ else None sql, tz_params = connection.ops.datetime_cast_date_sql(lhs, tzname) lhs_params.extend(tz_params) return sql, lhs_params
Example #11
Source File: lookups.py From openhgsenti with Apache License 2.0 | 5 votes |
def as_sql(self, compiler, connection): sql, params = compiler.compile(self.lhs) lhs_output_field = self.lhs.output_field if isinstance(lhs_output_field, DateTimeField): tzname = timezone.get_current_timezone_name() if settings.USE_TZ else None sql, tz_params = connection.ops.datetime_extract_sql(self.lookup_name, sql, tzname) params.extend(tz_params) elif isinstance(lhs_output_field, DateField): sql = connection.ops.date_extract_sql(self.lookup_name, sql) elif isinstance(lhs_output_field, TimeField): sql = connection.ops.time_extract_sql(self.lookup_name, sql) else: raise ValueError('DateTransform only valid on Date/Time/DateTimeFields') return sql, params
Example #12
Source File: context_processors.py From openhgsenti with Apache License 2.0 | 5 votes |
def tz(request): from django.utils import timezone return {'TIME_ZONE': timezone.get_current_timezone_name()}
Example #13
Source File: tz.py From python2017 with MIT License | 5 votes |
def render(self, context): context[self.variable] = timezone.get_current_timezone_name() return ''
Example #14
Source File: cache.py From python2017 with MIT License | 5 votes |
def _i18n_cache_key_suffix(request, cache_key): """If necessary, adds the current locale or time zone to the cache key.""" if settings.USE_I18N or settings.USE_L10N: # first check if LocaleMiddleware or another middleware added # LANGUAGE_CODE to request, then fall back to the active language # which in turn can also fall back to settings.LANGUAGE_CODE cache_key += '.%s' % getattr(request, 'LANGUAGE_CODE', get_language()) if settings.USE_TZ: # The datetime module doesn't restrict the output of tzname(). # Windows is known to use non-standard, locale-dependent names. # User-defined tzinfo classes may return absolutely anything. # Hence this paranoid conversion to create a valid cache key. tz_name = force_text(get_current_timezone_name(), errors='ignore') cache_key += '.%s' % tz_name.encode('ascii', 'ignore').decode('ascii').replace(' ', '_') return cache_key
Example #15
Source File: datetime.py From python with Apache License 2.0 | 5 votes |
def get_tzname(self): # Timezone conversions must happen to the input datetime *before* # applying a function. 2015-12-31 23:00:00 -02:00 is stored in the # database as 2016-01-01 01:00:00 +00:00. Any results should be # based on the input datetime not the stored datetime. tzname = None if settings.USE_TZ: if self.tzinfo is None: tzname = timezone.get_current_timezone_name() else: tzname = timezone._get_timezone_name(self.tzinfo) return tzname
Example #16
Source File: datetime.py From python2017 with MIT License | 5 votes |
def as_sql(self, compiler, connection): # Cast to date rather than truncate to date. lhs, lhs_params = compiler.compile(self.lhs) tzname = timezone.get_current_timezone_name() if settings.USE_TZ else None sql, tz_params = connection.ops.datetime_cast_date_sql(lhs, tzname) lhs_params.extend(tz_params) return sql, lhs_params
Example #17
Source File: datetime.py From python2017 with MIT License | 5 votes |
def as_sql(self, compiler, connection): # Cast to date rather than truncate to date. lhs, lhs_params = compiler.compile(self.lhs) tzname = timezone.get_current_timezone_name() if settings.USE_TZ else None sql, tz_params = connection.ops.datetime_cast_time_sql(lhs, tzname) lhs_params.extend(tz_params) return sql, lhs_params
Example #18
Source File: test_timezone.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_override_string_tz(self): with timezone.override('Asia/Bangkok'): self.assertEqual(timezone.get_current_timezone_name(), 'Asia/Bangkok')
Example #19
Source File: test_timezone.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_override_fixed_offset(self): with timezone.override(timezone.FixedOffset(0, 'tzname')): self.assertEqual(timezone.get_current_timezone_name(), 'tzname')
Example #20
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_cache_key_i18n_timezone(self): request = self.factory.get(self.path) tz = timezone.get_current_timezone_name() response = HttpResponse() key = learn_cache_key(request, response) self.assertIn(tz, key, "Cache keys should include the time zone name when time zones are active") key2 = get_cache_key(request) self.assertEqual(key, key2)
Example #21
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_cache_key_no_i18n(self): request = self.factory.get(self.path) lang = translation.get_language() tz = timezone.get_current_timezone_name() response = HttpResponse() key = learn_cache_key(request, response) self.assertNotIn(lang, key, "Cache keys shouldn't include the language name when i18n isn't active") self.assertNotIn(tz, key, "Cache keys shouldn't include the time zone name when i18n isn't active")
Example #22
Source File: test_timezone.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_override_string_tz(self): with timezone.override('Asia/Bangkok'): self.assertEqual(timezone.get_current_timezone_name(), 'Asia/Bangkok')
Example #23
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_cache_key_i18n_timezone(self): request = self.factory.get(self.path) tz = timezone.get_current_timezone_name() response = HttpResponse() key = learn_cache_key(request, response) self.assertIn(tz, key, "Cache keys should include the time zone name when time zones are active") key2 = get_cache_key(request) self.assertEqual(key, key2)
Example #24
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_cache_key_no_i18n(self): request = self.factory.get(self.path) lang = translation.get_language() tz = timezone.get_current_timezone_name() response = HttpResponse() key = learn_cache_key(request, response) self.assertNotIn(lang, key, "Cache keys shouldn't include the language name when i18n isn't active") self.assertNotIn(tz, key, "Cache keys shouldn't include the time zone name when i18n isn't active")
Example #25
Source File: test_middleware.py From ls.joyous with BSD 3-Clause "New" or "Revised" License | 5 votes |
def testLogInLogOut(self): self.assertEqual(get_current_timezone_name(), "Asia/Tokyo") self._login() self.assertEqual(get_current_timezone_name(), "America/Toronto") self._logout() self.assertEqual(get_current_timezone_name(), "Asia/Tokyo")
Example #26
Source File: datetime.py From bioforum with MIT License | 5 votes |
def as_sql(self, compiler, connection): # Cast to date rather than truncate to date. lhs, lhs_params = compiler.compile(self.lhs) tzname = timezone.get_current_timezone_name() if settings.USE_TZ else None sql = connection.ops.datetime_cast_date_sql(lhs, tzname) return sql, lhs_params
Example #27
Source File: cache.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def _i18n_cache_key_suffix(request, cache_key): """If necessary, adds the current locale or time zone to the cache key.""" if settings.USE_I18N or settings.USE_L10N: # first check if LocaleMiddleware or another middleware added # LANGUAGE_CODE to request, then fall back to the active language # which in turn can also fall back to settings.LANGUAGE_CODE cache_key += '.%s' % getattr(request, 'LANGUAGE_CODE', get_language()) if settings.USE_TZ: # The datetime module doesn't restrict the output of tzname(). # Windows is known to use non-standard, locale-dependent names. # User-defined tzinfo classes may return absolutely anything. # Hence this paranoid conversion to create a valid cache key. tz_name = force_text(get_current_timezone_name(), errors='ignore') cache_key += '.%s' % tz_name.encode('ascii', 'ignore').decode('ascii').replace(' ', '_') return cache_key
Example #28
Source File: lookups.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def process_lhs(self, compiler, connection, lhs=None): from django.db.models import DateTimeField lhs, params = super(DateLookup, self).process_lhs(compiler, connection, lhs) if isinstance(self.lhs.output_field, DateTimeField): tzname = timezone.get_current_timezone_name() if settings.USE_TZ else None sql, tz_params = connection.ops.datetime_extract_sql(self.extract_type, lhs, tzname) return connection.ops.lookup_cast(self.lookup_name) % sql, tz_params else: return connection.ops.date_extract_sql(self.lookup_name, lhs), []
Example #29
Source File: context_processors.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def tz(request): from django.utils import timezone return {'TIME_ZONE': timezone.get_current_timezone_name()}
Example #30
Source File: test_xform_viewset.py From kobo-predict with BSD 2-Clause "Simplified" License | 5 votes |
def test_submission_count_for_today_in_form_list(self): self._publish_xls_form_to_project() request = self.factory.get('/', **self.extra) response = self.view(request) self.assertEqual(response.status_code, 200) self.assertIn('submission_count_for_today', response.data[0].keys()) self.assertEqual(response.data[0]['submission_count_for_today'], 0) self.assertEqual(response.data[0]['num_of_submissions'], 0) paths = [os.path.join( self.main_directory, 'fixtures', 'transportation', 'instances_w_uuid', s, s + '.xml') for s in ['transport_2011-07-25_19-05-36']] # instantiate date that is NOT naive; timezone is enabled current_timzone_name = timezone.get_current_timezone_name() current_timezone = pytz.timezone(current_timzone_name) today = datetime.today() current_date = current_timezone.localize( datetime(today.year, today.month, today.day)) self._make_submission(paths[0], forced_submission_time=current_date) self.assertEqual(self.response.status_code, 201) request = self.factory.get('/', **self.extra) response = self.view(request) self.assertEqual(response.status_code, 200) self.assertEqual(response.data[0]['submission_count_for_today'], 1) self.assertEqual(response.data[0]['num_of_submissions'], 1)