当前位置: 首页>>代码示例>>Python>>正文


Python timezone.get_current_timezone_name方法代码示例

本文整理汇总了Python中django.utils.timezone.get_current_timezone_name方法的典型用法代码示例。如果您正苦于以下问题:Python timezone.get_current_timezone_name方法的具体用法?Python timezone.get_current_timezone_name怎么用?Python timezone.get_current_timezone_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.timezone的用法示例。


在下文中一共展示了timezone.get_current_timezone_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_instance_bound

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
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

# ------------------------------------------------------------------------------ 
开发者ID:linuxsoftware,项目名称:ls.joyous,代码行数:18,代码来源:edit_handlers.py

示例2: render

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
def render(self, context):
        context[self.variable] = timezone.get_current_timezone_name()
        return '' 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:5,代码来源:tz.py

示例3: _i18n_cache_key_suffix

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
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 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:17,代码来源:cache.py

示例4: process_lhs

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
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), [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:11,代码来源:lookups.py

示例5: tz

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
def tz(request):
    from django.utils import timezone

    return {'TIME_ZONE': timezone.get_current_timezone_name()} 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:context_processors.py

示例6: test_submission_count_for_today_in_form_list

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
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) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:33,代码来源:test_xform_viewset.py

示例7: submission_count_for_today

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
def submission_count_for_today(self):
        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))
        count = self.instances.filter(
            deleted_at__isnull=True,
            date_created=current_date).count()
        return count 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:14,代码来源:xform.py

示例8: test_missing_session

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
def test_missing_session(self):
        request = self.request_factory.get('/')
        self.middleware.process_request(request)
        self.assertEqual(timezone.get_current_timezone_name(), settings.TIME_ZONE) 
开发者ID:charettes,项目名称:django-sundial,代码行数:6,代码来源:test_middleware.py

示例9: test_missing_session_timezone

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
def test_missing_session_timezone(self):
        request = self.request_factory.get('/')
        self.session_middleware.process_request(request)
        self.middleware.process_request(request)
        self.assertEqual(timezone.get_current_timezone_name(), settings.TIME_ZONE) 
开发者ID:charettes,项目名称:django-sundial,代码行数:7,代码来源:test_middleware.py

示例10: test_timezone_activation

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
def test_timezone_activation(self):
        request = self.request_factory.get('/')
        self.session_middleware.process_request(request)
        zone = 'America/Montreal'
        set_session_timezone(request.session, zone)
        self.middleware.process_request(request)
        self.assertEqual(timezone.get_current_timezone_name(), zone) 
开发者ID:charettes,项目名称:django-sundial,代码行数:9,代码来源:test_middleware.py

示例11: _i18n_cache_key_suffix

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
def _i18n_cache_key_suffix(request, cache_key):
    """If necessary, add 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 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:17,代码来源:cache.py

示例12: get_tzname

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
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 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:14,代码来源:datetime.py

示例13: as_sql

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
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 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:8,代码来源:datetime.py

示例14: testTimeZone

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
def testTimeZone(self):
        #tzname = request.session.get('django_timezone')
        response = self.client.get('/')
        self.failUnlessEqual(response.status_code, status.HTTP_200_OK)

        # If not loggedin, no timezone in session
        session = self.client.session
        self.assertFalse('django_timezone' in session)

        ok = self.client.login(email='user1@foo.com', password='pass')
        self.assertTrue(ok)
        response = self.client.get('/')
        self.failUnlessEqual(response.status_code, status.HTTP_200_OK)

        # Default Time zone
        session = self.client.session
        self.assertTrue('django_timezone' in session)
        self.assertEqual(session["django_timezone"], timezone.get_default_timezone_name())

        self.client.logout()

        u4 = user_model.objects.create_user(username='user4', email='user4@foo.com', password='pass')
        u4.name = 'New York Dude'
        u4.time_zone = 'America/New_York'
        u4.is_active = True
        u4.save()

        ok = self.client.login(email='user4@foo.com', password='pass')
        self.assertTrue(ok)
        response = self.client.get('/')
        self.failUnlessEqual(response.status_code, status.HTTP_200_OK)

        # Default Time zone
        session = self.client.session
        self.assertTrue('django_timezone' in session)
        self.assertEqual(session["django_timezone"], timezone.get_current_timezone_name())
        self.assertEqual(timezone.get_current_timezone_name(), 'America/New_York')

        self.client.logout() 
开发者ID:dkarchmer,项目名称:django-aws-template,代码行数:41,代码来源:tests.py

示例15: email_on_new_login

# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import get_current_timezone_name [as 别名]
def email_on_new_login(sender: Any, user: UserProfile, request: Any, **kwargs: Any) -> None:
    if not user.enable_login_emails:
        return
    # We import here to minimize the dependencies of this module,
    # since it runs as part of `manage.py` initialization
    from zerver.context_processors import common_context

    if not settings.SEND_LOGIN_EMAILS:
        return

    if request:
        # If the user's account was just created, avoid sending an email.
        if (timezone_now() - user.date_joined).total_seconds() <= JUST_CREATED_THRESHOLD:
            return

        user_agent = request.META.get('HTTP_USER_AGENT', "").lower()

        context = common_context(user)
        context['user_email'] = user.delivery_email
        user_tz = user.timezone
        if user_tz == '':
            user_tz = timezone_get_current_timezone_name()
        local_time = timezone_now().astimezone(get_timezone(user_tz))
        if user.twenty_four_hour_time:
            hhmm_string = local_time.strftime('%H:%M')
        else:
            hhmm_string = local_time.strftime('%I:%M%p')
        context['login_time'] = local_time.strftime(f'%A, %B %d, %Y at {hhmm_string} %Z')
        context['device_ip'] = request.META.get('REMOTE_ADDR') or _("Unknown IP address")
        context['device_os'] = get_device_os(user_agent) or _("an unknown operating system")
        context['device_browser'] = get_device_browser(user_agent) or _("An unknown browser")
        context['unsubscribe_link'] = one_click_unsubscribe_link(user, 'login')

        email_dict = {
            'template_prefix': 'zerver/emails/notify_new_login',
            'to_user_ids': [user.id],
            'from_name': FromAddress.security_email_from_name(user_profile=user),
            'from_address': FromAddress.NOREPLY,
            'context': context}
        queue_json_publish("email_senders", email_dict) 
开发者ID:zulip,项目名称:zulip,代码行数:42,代码来源:signals.py


注:本文中的django.utils.timezone.get_current_timezone_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。