當前位置: 首頁>>代碼示例>>Python>>正文


Python timezone.get_default_timezone_name方法代碼示例

本文整理匯總了Python中django.utils.timezone.get_default_timezone_name方法的典型用法代碼示例。如果您正苦於以下問題:Python timezone.get_default_timezone_name方法的具體用法?Python timezone.get_default_timezone_name怎麽用?Python timezone.get_default_timezone_name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.utils.timezone的用法示例。


在下文中一共展示了timezone.get_default_timezone_name方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: question_score

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import get_default_timezone_name [as 別名]
def question_score(question):
    creation_date = question.pub_date
    score = question.total_points
    answers_positive_points = list(
        question.answer_set.all().values_list(
            'answervote__value', flat=True)).count(True)
    answers_negative_points = list(
        question.answer_set.all().values_list(
            'answervote__value', flat=True)).count(False)
    score = score * 2 + answers_positive_points - answers_negative_points
    reference_date = pytz.timezone(
        timezone.get_default_timezone_name()).localize(datetime(1970, 1, 1))
    difference = creation_date - reference_date
    difference_seconds = difference.days * 86400 + difference.seconds +\
        (float(difference.microseconds) / 1000000)
    order = log(max(abs(score), 1), 10)
    sign = 1 if score > 0 else -1 if score < 0 else 0
    seconds = difference_seconds - 1134028003
    return round(sign * order + seconds / 45000, 7) 
開發者ID:arjunkomath,項目名稱:Simple-Q-A-App-using-Python-Django,代碼行數:21,代碼來源:utils.py

示例2: about_view

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import get_default_timezone_name [as 別名]
def about_view(request):
    g = hszinc.Grid()
    g.column['vendorUri'] = {}
    g.column['productUri'] = {}
    g.column['tz'] = {}
    g.column['serverName'] = {}
    g.column['productName'] = {}
    g.column['haystackVersion'] = {}
    g.column['productVersion'] = {}
    g.column['serverTime'] = {}
    g.column['serverBootTime'] = {}
    g.column['vendorName'] = {}
    g.extend([{
        'vendorUri': 'https://www.opensourcestrategies.com',
        'productUri': 'https://www.opensourcestrategies.com',
        'tz': timezone.get_default_timezone_name(),
        'serverName': Site.objects.get_current().domain,
        'productName': 'Opentaps-SEAS Haystack',
        'haystackVersion': '2.0',
        'productVersion': '1.0',
        'serverTime': timezone.now(),
        'vendorName': 'Opentaps-SEAS Haystack'
    }])
    return _hzinc_response(g) 
開發者ID:opentaps,項目名稱:opentaps_seas,代碼行數:26,代碼來源:views.py

示例3: testTimeZone

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import get_default_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

示例4: test_multitenant_chat_consumer

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import get_default_timezone_name [as 別名]
def test_multitenant_chat_consumer():
    settings.CHANNEL_LAYERS = TEST_CHANNEL_LAYERS
    client, room, user = prepare_room_and_user()
    communicator = WebsocketCommunicator(
        multitenant_application, f"/ws/django_chatter/chatrooms/{room.id}/",
        headers=[
            (
                b'cookie',
                f'sessionid={client.cookies["sessionid"].value}'.encode('ascii')
            ),
            (b'host', b'localhost:8000')]
        )
    connected, subprotocol = await communicator.connect()
    assert connected
    data = {
        'message_type': 'text',
        'message': "Hello!",
        'sender': user.username,
        'room_id': str(room.id),
        }
    await communicator.send_json_to(data)
    response = await communicator.receive_json_from()
    response = response
    message = Message.objects.all()[0]
    time = message.date_created
    # zone = pytz.timezone(get_default_timezone_name())
    # time = time.astimezone(tz=zone)
    # formatted = dateformat.DateFormat(time)
    # time = formatted.format('M d, Y h:i a')

    assert response['message_type'] == 'text'
    assert response['message'] == 'Hello!'
    assert response['sender'] == 'user0'
    assert response['room_id'] == str(room.id)
    assert response['date_created'] == time.strftime("%d %b %Y %H:%M:%S %Z")
    await communicator.disconnect() 
開發者ID:dibs-devs,項目名稱:chatter,代碼行數:38,代碼來源:test_consumers.py

示例5: test_get_default_timezone

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import get_default_timezone_name [as 別名]
def test_get_default_timezone(self):
        self.assertEqual(timezone.get_default_timezone_name(), 'America/Chicago') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:test_timezone.py


注:本文中的django.utils.timezone.get_default_timezone_name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。