本文整理汇总了Python中django.utils.dateformat.DateFormat.format方法的典型用法代码示例。如果您正苦于以下问题:Python DateFormat.format方法的具体用法?Python DateFormat.format怎么用?Python DateFormat.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.dateformat.DateFormat
的用法示例。
在下文中一共展示了DateFormat.format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: date_as_block_filter
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def date_as_block_filter(value):
df = DateFormat(value)
result = '''<{0} class="day">{1}</{0}>
<{0} class="month">{2}</{0}>
<{0} class="year">{3}</{0}>'''.format(
'span', df.format('d'), df.format('M'), df.format('Y'))
return mark_safe(result)
示例2: get_value
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def get_value(self, value):
if isinstance(value, date):
date_format = DateFormat(value)
return date_format.format("d/m/y").capitalize()
elif isinstance(value, datetime):
date_format = DateFormat(value)
return date_format.format("d/m/y H:M").capitalize()
return value
示例3: occurrences
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def occurrences(request):
user = User.objects.get(id=request.user.id)
occurrences_objects = Occurrences.objects.filter(
user=user, bullshit=0).order_by('created_at')
forcing_objects = OccurrencesReforce.objects.filter(user=user)
result = []
# query for own occurrences
if (len(occurrences_objects) > 0):
for occ in occurrences_objects:
df = DateFormat(occ.created_at)
new_date = df.format('m/d/Y H:i:s')
o = {'is_owner': 1,
'id': occ.id,
'user_id': occ.user_id,
'user_name': user.username,
'created_at': str(new_date),
'coordinate': occ.coordinate,
'category_id': occ.category_id,
'forced': 0,
'category_name': occ.category.name,
'title': occ.title,
'description': occ.description,
'validated': occ.validated,
'vote_counter': occ.vote_counter}
result.append(o)
# query for occurrences user follows
if(forcing_objects.exists()):
for forcing in forcing_objects:
occ = forcing.occurrence
df = DateFormat(occ.created_at)
new_date = df.format('m/d/Y H:i:s')
perm = has_write_permission(occ.id, request.user.id)
o = {'permission': perm,
'is_owner': 0,
'id': occ.id,
'user_id': occ.user_id,
'user_name': occ.user.username,
'created_at': str(new_date),
'coordinate': occ.coordinate,
'category_id': occ.category_id,
'forced': 1,
'category_name': occ.category.name,
'title': occ.title,
'description': occ.description,
'validated': occ.validated,
'vote_counter': occ.vote_counter}
result.append(o)
return HttpResponse(simplejson.dumps(result), content_type="json")
示例4: format_story_link_date__long
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def format_story_link_date__long(date, now=None):
if not now: now = datetime.datetime.utcnow()
diff = now.date() - date.date()
parsed_date = DateFormat(date)
if diff.days == 0:
return 'Today, ' + parsed_date.format('F jS ') + date.strftime('%I:%M%p').lstrip('0').lower()
elif diff.days == 1:
return 'Yesterday, ' + parsed_date.format('F jS g:ia').replace('.','')
elif date.date().timetuple()[7] == now.date().timetuple()[7]:
return parsed_date.format('l, F jS g:ia').replace('.','')
else:
return parsed_date.format('l, F jS, Y g:ia').replace('.','')
示例5: format_story_link_date__long
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def format_story_link_date__long(date, now=None):
if not now:
now = datetime.datetime.utcnow()
diff = now.date() - date.date()
parsed_date = DateFormat(date)
if diff.days == 0:
return "Today, " + parsed_date.format("F jS ") + date.strftime("%I:%M%p").lstrip("0").lower()
elif diff.days == 1:
return "Yesterday, " + parsed_date.format("F jS g:ia").replace(".", "")
elif date.date().timetuple()[7] == now.date().timetuple()[7]:
return parsed_date.format("l, F jS g:ia").replace(".", "")
else:
return parsed_date.format("l, F jS, Y g:ia").replace(".", "")
示例6: format_story_link_date__long
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def format_story_link_date__long(date, now=None):
if not now:
now = datetime.datetime.now()
date = date.replace(tzinfo=None)
midnight = midnight_today(now)
parsed_date = DateFormat(date)
if date >= midnight:
return "Today, " + parsed_date.format("F jS ") + date.strftime("%I:%M%p").lstrip("0").lower()
elif date >= midnight_yesterday(midnight):
return "Yesterday, " + parsed_date.format("F jS g:ia").replace(".", "")
elif date >= beginning_of_this_month():
return parsed_date.format("l, F jS g:ia").replace(".", "")
else:
return parsed_date.format("l, F jS, Y g:ia").replace(".", "")
示例7: format_story_link_date__long
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def format_story_link_date__long(date, now=None):
if not now:
now = datetime.datetime.now()
date = date.replace(tzinfo=None)
midnight = midnight_today(now)
parsed_date = DateFormat(date)
if date >= midnight:
return 'Today, ' + parsed_date.format('F jS ') + date.strftime('%I:%M%p').lstrip('0').lower()
elif date >= midnight_yesterday(midnight):
return 'Yesterday, ' + parsed_date.format('F jS g:ia').replace('.','')
elif date >= beginning_of_this_month():
return parsed_date.format('l, F jS g:ia').replace('.','')
else:
return parsed_date.format('l, F jS, Y g:ia').replace('.','')
示例8: recently_read
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def recently_read(**kwargs):
""" return html containing data from the recently read list
Specify an argument n=[int] to determine how many entries
are rendered in the list.
"""
num_entries = int(kwargs['n']) if 'n' in kwargs else lib.NUM_READ_LIST
read_list = ReadingListItem.objects.filter(wishlist=False).order_by('-date_published')[:num_entries]
list_html = format_html("<h3>Recently Read</h3><div class=\"book-list\">")
for book in read_list:
list_html += format_html("<div class='book-book-result book-book-result-hover group'>")
list_html += format_html("<img src='{}' class='left'>", book.cover)
list_html += format_html("<p class='title'>{}</p>", book.title)
list_html += format_html("<p class='author'>{}</p>", book.author)
list_html += format_html("<p class='description'>{}</p>", book.description)
dt = DateFormat(book.date_published)
list_html += format_html("<p class='date'>Added on {}</p>", dt.format("F j, Y g:i A"))
if book.favorite:
list_html += format_html("<span class='favorite' title='Cory\'s Favorites'>★</span>")
list_html += format_html("<a class='overlay' href='{}' target='_blank'></a></div>", book.link)
if len(read_list) == 0:
list_html += format_html("<p class='empty'>Cory hasn't read any books yet!</p>")
list_html += format_html("<p class='empty'><a href='{}'>(See More)</a></p></div>", reverse('books'))
return list_html
示例9: places
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def places(request):
context_dict = {}
if request.method == 'POST':
from_station = request.POST.get('from_station')
to_station = request.POST.get('to_station')
date = request.POST.get('departure_date')
time = request.POST.get('departure_time')
train_number = request.POST.get('train_number')
departure_date = datetime.strptime(date, "%Y-%m-%d")
client = Client(api_usernumber = conf.USER_NUMBER, api_passmd5 = conf.USER_PASSMD5, id_terminal = conf.ID_TERMINAL, id_service = conf.ID_SERVICE, request_url = conf.API_URL)
df = DateFormat(departure_date)
places = client.get_train_places(from_station, to_station, df.format('d.m.Y'), time, train_number)
data = json.dumps(places, ensure_ascii=False)
response_dict = json.loads(data)
if 'status' in response_dict:
context_dict['error'] = response_dict['message']
else:
context_dict = place_handler(response_dict)
context_dict['data'] = data
context_dict['from_station'] = Station.objects.get(code=from_station)
context_dict['to_station'] = Station.objects.get(code=to_station)
context_dict['departure_date'] = date
context_dict['departure_time'] = time
context_dict['train_number'] = train_number
context_dict['stations'] = Station.objects.all()
return render(request, 'search/places.html', context_dict)
示例10: _format_json_list
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def _format_json_list(self, obj, options):
if (len(obj) > 0):
result = []
for occ in obj:
df = DateFormat(occ.created_at)
new_date = df.format('m/d/Y H:i:s')
o = { 'is_owner': is_owner(occ.id, options['request_user_id']),
'id': occ.id,
'user_id': occ.user_id,
'created_at': str(new_date),
'coordinate': occ.coordinate,
'category_id': occ.category_id,
'category_name': occ.category.name,
'title': occ.title,
'description': occ.description,
'validated': occ.validated,
'vote_counter': occ.vote_counter
}
result.append(o)
return simplejson.dumps(result)
else:
return simplejson.dumps({'Success': False})
示例11: get_occurrence
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def get_occurrence(request, ident, user):
result = {}
result["success"] = False
path = settings.CDN_URL + "/static/"
occ = Occurrences.objects.get(id=int(ident))
df = DateFormat(occ.created_at)
new_date = df.format('m/d/Y H:i:s')
result["occurrence"] = {'id_occ': occ.id,
'user_id': occ.user_id,
'created_at': str(new_date),
'coordinate': occ.coordinate,
'category_id': occ.category_id,
'category_name': occ.category.name,
'title': occ.title,
'description': occ.description,
'vote_counter': occ.vote_counter}
occ_photos = occ.photos_set.all()
result["occurrence"]["photos"] = []
userObj = User.objects.get(id=int(user))
result["occurrence"]["is_following"] = is_following(occ, userObj)
for photo in occ_photos:
result["occurrence"]["photos"].append(
{"path_small": path + photo.path_small,
"path_big": path + photo.path_big,
"path_medium": path + photo.path_medium})
result["success"] = True
return HttpResponse(simplejson.dumps(result), content_type="json")
示例12: test_list_measurement
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def test_list_measurement(admin_client, live_server, # pylint: disable=R0914
webdriver):
selenium = webdriver()
create_correct_sample_data()
create_characteristic_values()
try:
selenium.get(live_server + '/measurement/')
login_as_admin(selenium)
title = selenium.find_element_by_css_selector('#page-wrapper h1').text
assert title == 'List of measurements'
table_rows = selenium.find_elements_by_class_name('clickable-row')
assert len(table_rows) == 19
all_meas = Measurement.objects.all()
header = selenium.find_elements_by_css_selector('#page-wrapper th')
assert len(header) == 6
for index, field_name in enumerate(['date', 'order', 'order_items',
'examiner', 'meas_item',
'measurement_tag']):
field = Measurement._meta.get_field(field_name) # pylint: disable=W0212
assert header[index].text == field.verbose_name
for index, row in enumerate(table_rows):
url = '/measurement/{}/'.format(all_meas[index].pk)
assert row.get_attribute('data-href') == url
columns = row.find_elements_by_css_selector('#page-wrapper td')
assert len(columns) == 6
date = DateFormat(all_meas[index].date)
assert columns[0].text == date.format(settings.DATETIME_FORMAT)
assert columns[1].text == str(all_meas[index].order).strip()
items = all_meas[index].order_items.all()
assert columns[2].text == ';'.join([str(item) for item in items])
assert columns[3].text == all_meas[index].examiner.username
assert columns[4].text == str(all_meas[index].meas_item)
assert columns[5].text == str(all_meas[index].measurement_tag)
finally:
selenium.quit()
示例13: get_initial
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def get_initial(self):
self.year = int(self.kwargs["year"])
self.month = int(self.kwargs["month"])
self.day = int(self.kwargs["day"])
dt = date(self.year, self.month, self.day)
df = DateFormat(dt)
return {'date': date(self.year, self.month, self.day), 'title': ("%s -" % df.format('F jS')), 'user':self.request.user.username}
示例14: serialize_for_ajax
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def serialize_for_ajax(self):
""" Serializes the time, puzzle, team, and status fields for ajax transmission """
message = dict()
df = DateFormat(self.submission_time.astimezone(time_zone))
message['time_str'] = df.format("h:i a")
message['puzzle'] = self.puzzle.serialize_for_ajax()
message['team_pk'] = self.team.pk
message['status_type'] = "submission"
return message
示例15: server_time
# 需要导入模块: from django.utils.dateformat import DateFormat [as 别名]
# 或者: from django.utils.dateformat.DateFormat import format [as 别名]
def server_time(request):
""" AJAX call to get the current server time. """
if request.is_ajax():
df = DateFormat(datetime.now())
payload = df.format("F jS Y @ h:iA")
else:
payload = "Sorry, this URL is for AJAX calls only."
return HttpResponse(payload, mimetype="text/plain")