当前位置: 首页>>代码示例>>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;未经允许,请勿转载。