本文整理汇总了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)
示例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)
示例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()
示例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()
示例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')