本文整理汇总了Python中django.utils.dateformat.DateFormat方法的典型用法代码示例。如果您正苦于以下问题:Python dateformat.DateFormat方法的具体用法?Python dateformat.DateFormat怎么用?Python dateformat.DateFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.dateformat
的用法示例。
在下文中一共展示了dateformat.DateFormat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: entries_by_date
# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import DateFormat [as 别名]
def entries_by_date(self, request, year, month=None, day=None, *args, **kwargs):
self.entries = self.get_entries().filter(date__year=year)
self.search_type = _('date')
self.search_term = year
if month:
self.entries = self.entries.filter(date__month=month)
df = DateFormat(date(int(year), int(month), 1))
self.search_term = df.format('F Y')
if day:
self.entries = self.entries.filter(date__day=day)
self.search_term = date_format(date(int(year), int(month), int(day)))
return Page.serve(self, request, *args, **kwargs)
示例2: test_multitenant_chat_consumer
# 需要导入模块: from django.utils import dateformat [as 别名]
# 或者: from django.utils.dateformat import DateFormat [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()