mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
[1.5.x] Fixed #19015 -- Add ISO input formats to all formats
Backport of 349c4c37f8 from master.
This commit is contained in:
@@ -17,16 +17,12 @@ FIRST_DAY_OF_WEEK = 1 # Monday
|
||||
# see http://docs.python.org/library/datetime.html#strftime-strptime-behavior
|
||||
DATE_INPUT_FORMATS = (
|
||||
'%d.%m.%Y', '%d.%m.%y', # '25.10.2006', '25.10.06'
|
||||
'%Y-%m-%d', '%y-%m-%d', # '2006-10-25', '06-10-25'
|
||||
# '%d. %B %Y', '%d. %b. %Y', # '25. October 2006', '25. Oct. 2006'
|
||||
)
|
||||
DATETIME_INPUT_FORMATS = (
|
||||
'%d.%m.%Y %H:%M:%S', # '25.10.2006 14:30:59'
|
||||
'%d.%m.%Y %H:%M', # '25.10.2006 14:30'
|
||||
'%d.%m.%Y', # '25.10.2006'
|
||||
'%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59'
|
||||
'%Y-%m-%d %H:%M', # '2006-10-25 14:30'
|
||||
'%Y-%m-%d', # '2006-10-25'
|
||||
)
|
||||
DECIMAL_SEPARATOR = ','
|
||||
THOUSAND_SEPARATOR = '.'
|
||||
|
||||
@@ -16,6 +16,17 @@ from django.utils.translation import get_language, to_locale, check_for_language
|
||||
_format_cache = {}
|
||||
_format_modules_cache = {}
|
||||
|
||||
ISO_INPUT_FORMATS = {
|
||||
'DATE_INPUT_FORMATS': ('%Y-%m-%d',),
|
||||
'TIME_INPUT_FORMATS': ('%H:%M:%S', '%H:%M'),
|
||||
'DATETIME_INPUT_FORMATS': (
|
||||
'%Y-%m-%d %H:%M:%S',
|
||||
'%Y-%m-%d %H:%M:%S.%f',
|
||||
'%Y-%m-%d %H:%M',
|
||||
'%Y-%m-%d'
|
||||
),
|
||||
}
|
||||
|
||||
def reset_format_cache():
|
||||
"""Clear any cached formats.
|
||||
|
||||
@@ -82,6 +93,11 @@ def get_format(format_type, lang=None, use_l10n=None):
|
||||
for module in get_format_modules(lang):
|
||||
try:
|
||||
val = getattr(module, format_type)
|
||||
for iso_input in ISO_INPUT_FORMATS.get(format_type, ()):
|
||||
if iso_input not in val:
|
||||
if isinstance(val, tuple):
|
||||
val = list(val)
|
||||
val.append(iso_input)
|
||||
_format_cache[cache_key] = val
|
||||
return val
|
||||
except AttributeError:
|
||||
|
||||
Reference in New Issue
Block a user