From 1a1264f1494976c562c7cb832fe47f3e1e765b8f Mon Sep 17 00:00:00 2001 From: Manatsawin Hanmongkolchai Date: Sun, 11 Feb 2018 04:05:41 +0700 Subject: [PATCH] Fixed #29109 -- Fixed the admin time picker widget for the Thai locale. --- django/conf/locale/th/formats.py | 4 ++-- docs/releases/2.0.3.txt | 4 ++++ tests/i18n/tests.py | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/django/conf/locale/th/formats.py b/django/conf/locale/th/formats.py index d4f478e0c1..5a980f097c 100644 --- a/django/conf/locale/th/formats.py +++ b/django/conf/locale/th/formats.py @@ -19,13 +19,13 @@ DATE_INPUT_FORMATS = [ '%d %B %Y', # 25 ตุลาคม 2006 ] TIME_INPUT_FORMATS = [ - '%H:%M:%S.%f', # 14:30:59.000200 '%H:%M:%S', # 14:30:59 + '%H:%M:%S.%f', # 14:30:59.000200 '%H:%M', # 14:30 ] DATETIME_INPUT_FORMATS = [ - '%d/%m/%Y %H:%M:%S.%f', # 25/10/2006 14:30:59.000200 '%d/%m/%Y %H:%M:%S', # 25/10/2006 14:30:59 + '%d/%m/%Y %H:%M:%S.%f', # 25/10/2006 14:30:59.000200 '%d/%m/%Y %H:%M', # 25/10/2006 14:30 ] DECIMAL_SEPARATOR = '.' diff --git a/docs/releases/2.0.3.txt b/docs/releases/2.0.3.txt index 4fbca2e247..277cab7573 100644 --- a/docs/releases/2.0.3.txt +++ b/docs/releases/2.0.3.txt @@ -11,3 +11,7 @@ Bugfixes * Fixed a regression that caused sliced ``QuerySet.distinct().order_by()`` followed by ``count()`` to crash (:ticket:`29108`). + +* Prioritized the datetime and time input formats without ``%f`` for the Thai + locale to fix the admin time picker widget displaying "undefined" + (:ticket:`29109`). diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index b9aa0cad55..e195bb4f52 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -3,6 +3,7 @@ import decimal import gettext as gettext_module import os import pickle +import re from contextlib import contextmanager from importlib import import_module from threading import local @@ -1095,6 +1096,22 @@ class FormattingTests(SimpleTestCase): with translation.override('fr', deactivate=True): self.assertEqual('d/m/Y CUSTOM', get_format('CUSTOM_DAY_FORMAT')) + def test_admin_javascript_supported_input_formats(self): + """ + The first input format for DATE_INPUT_FORMATS, TIME_INPUT_FORMATS, and + DATETIME_INPUT_FORMATS must not contain %f since that's unsupported by + the admin's time picker widget. + """ + regex = re.compile('%([^BcdHImMpSwxXyY%])') + for language_code, language_name in settings.LANGUAGES: + for format_name in ('DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS'): + with self.subTest(language=language_code, format=format_name): + formatter = get_format(format_name, lang=language_code)[0] + self.assertEqual( + regex.findall(formatter), [], + "%s locale's %s uses an unsupported format code." % (language_code, format_name) + ) + class MiscTests(SimpleTestCase):