當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。