本文整理匯總了Python中django.conf.settings.DATE_FORMAT屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.DATE_FORMAT屬性的具體用法?Python settings.DATE_FORMAT怎麽用?Python settings.DATE_FORMAT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.DATE_FORMAT屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: format_as_response
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATE_FORMAT [as 別名]
def format_as_response(self, *args):
unknown = {'course_id': None, 'count': 0, 'date': None,
'country': {'alpha2': None, 'alpha3': None, 'name': country.UNKNOWN_COUNTRY_CODE}}
for arg in args:
if arg.country.name == country.UNKNOWN_COUNTRY_CODE:
unknown['course_id'] = arg.course_id
unknown['date'] = arg.date.strftime(settings.DATE_FORMAT)
unknown['count'] += arg.count
unknown['created'] = arg.created.strftime(settings.DATETIME_FORMAT)
args = [arg for arg in args if arg.country != country.UNKNOWN_COUNTRY]
args = sorted(args, key=lambda item: (item.date, item.course_id, item.country.alpha3))
response = [unknown]
response += [
{'course_id': six.text_type(ce.course_id), 'count': ce.count,
'date': ce.date.strftime(settings.DATE_FORMAT),
'country': {'alpha2': ce.country.alpha2, 'alpha3': ce.country.alpha3, 'name': ce.country.name},
'created': ce.created.strftime(settings.DATETIME_FORMAT)} for ce in args
]
return response
示例2: _to_text
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATE_FORMAT [as 別名]
def _to_text(self, fieldsubmission=None, format=settings.DATE_FORMAT):
if fieldsubmission.data['info']:
d = datetime.datetime.strptime(fieldsubmission.data['info'], '%Y-%m-%d').date()
return escape(defaultfilters.date(d, format))
else:
return 'not entered'
示例3: date
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATE_FORMAT [as 別名]
def date(value, arg=None):
"""Formats a date according to the given format."""
if value in (None, ''):
return ''
if arg is None:
arg = settings.DATE_FORMAT
try:
return formats.date_format(value, arg)
except AttributeError:
try:
return format(value, arg)
except AttributeError:
return ''
示例4: format_last_updated_date_and_time
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATE_FORMAT [as 別名]
def format_last_updated_date_and_time(d):
return {'update_date': dateformat.format(d, settings.DATE_FORMAT),
'update_time': dateformat.format(d, settings.TIME_FORMAT)}
示例5: parse_date
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATE_FORMAT [as 別名]
def parse_date(self, date, timezone):
if date:
try:
date = datetime.datetime.strptime(date, settings.DATETIME_FORMAT)
except ValueError:
date = datetime.datetime.strptime(date, settings.DATE_FORMAT)
date = make_aware(date, timezone)
return date
示例6: assertIntervalFilteringWorks
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATE_FORMAT [as 別名]
def assertIntervalFilteringWorks(self, expected_response, course_id, start_date, end_date):
# If start date is after date of existing data, return a 404
date = (start_date + datetime.timedelta(days=30)).strftime(settings.DATETIME_FORMAT)
response = self.authenticated_get(
'%scourses/%s%s?start_date=%s' % (self.api_root_path, course_id, self.path, date))
self.assertEqual(response.status_code, 404)
# If end date is before date of existing data, return a 404
date = (start_date - datetime.timedelta(days=30)).strftime(settings.DATETIME_FORMAT)
response = self.authenticated_get(
'%scourses/%s%s?end_date=%s' % (self.api_root_path, course_id, self.path, date))
self.assertEqual(response.status_code, 404)
# If data falls in date range, data should be returned
start = start_date.strftime(settings.DATETIME_FORMAT)
end = end_date.strftime(settings.DATETIME_FORMAT)
response = self.authenticated_get('%scourses/%s%s?start_date=%s&end_date=%s' % (
self.api_root_path, course_id, self.path, start, end))
self.assertEqual(response.status_code, 200)
self.assertListEqual(response.data, expected_response)
# Passing dates in DATE_FORMAT still works
start = start_date.strftime(settings.DATE_FORMAT)
end = end_date.strftime(settings.DATE_FORMAT)
response = self.authenticated_get('%scourses/%s%s?start_date=%s&end_date=%s' % (
self.api_root_path, course_id, self.path, start, end))
self.assertEqual(response.status_code, 200)
self.assertListEqual(response.data, expected_response)
# pylint: disable=abstract-method
示例7: serialize_enrollment
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DATE_FORMAT [as 別名]
def serialize_enrollment(self, enrollment):
return {
'created': enrollment.created.strftime(settings.DATETIME_FORMAT),
'course_id': six.text_type(enrollment.course_id),
'date': enrollment.date.strftime(settings.DATE_FORMAT),
enrollment.cleaned_gender: enrollment.count
}