kopia lustrzana https://github.com/wagtail/wagtail
rodzic
9f246d5eae
commit
ca5d54cb89
|
@ -49,6 +49,7 @@ Changelog
|
|||
* Fix: Fix dynamic image serve view with certain backends (Sébastien Corbin)
|
||||
* Fix: Show not allowed extension in error message (Sahil Jangra)
|
||||
* Fix: Fix focal point chooser when localization enabled (Sébastien Corbin)
|
||||
* Fix: Ensure that system checks for `WAGTAIL_DATE_FORMAT`, `WAGTAIL_DATETIME_FORMAT` and `WAGTAIL_TIME_FORMAT` take `FORMAT_MODULE_PATH` into account (Sébastien Corbin)
|
||||
* Docs: Remove duplicate section on frontend caching proxies from performance page (Jake Howard)
|
||||
* Docs: Document `restriction_type` field on PageViewRestriction (Shlomo Markowitz)
|
||||
* Docs: Document Wagtail's bug bounty policy (Jake Howard)
|
||||
|
|
|
@ -79,6 +79,7 @@ This feature was implemented by Matt Westcott and Sage Abdullah.
|
|||
* Fix dynamic image serve view with certain backends (Sébastien Corbin)
|
||||
* Show not allowed extension in error message (Sahil Jangra)
|
||||
* Fix focal point chooser when localization enabled (Sébastien Corbin)
|
||||
* Ensure that system checks for `WAGTAIL_DATE_FORMAT`, `WAGTAIL_DATETIME_FORMAT` and `WAGTAIL_TIME_FORMAT` take `FORMAT_MODULE_PATH` into account (Sébastien Corbin)
|
||||
|
||||
### Documentation
|
||||
|
||||
|
|
|
@ -246,43 +246,33 @@ def datetime_format_check(app_configs, **kwargs):
|
|||
"""
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils import formats, translation
|
||||
from django.utils import formats
|
||||
|
||||
errors = []
|
||||
|
||||
if not getattr(settings, "USE_L10N", False):
|
||||
return errors
|
||||
|
||||
formats.FORMAT_SETTINGS = formats.FORMAT_SETTINGS.union(
|
||||
[
|
||||
"WAGTAIL_DATE_FORMAT",
|
||||
"WAGTAIL_DATETIME_FORMAT",
|
||||
"WAGTAIL_TIME_FORMAT",
|
||||
]
|
||||
)
|
||||
|
||||
for code, label in settings.LANGUAGES:
|
||||
with translation.override(code):
|
||||
for wagtail_format, django_formats in [
|
||||
("WAGTAIL_DATE_FORMAT", "DATE_INPUT_FORMATS"),
|
||||
("WAGTAIL_DATETIME_FORMAT", "DATETIME_INPUT_FORMATS"),
|
||||
("WAGTAIL_TIME_FORMAT", "TIME_INPUT_FORMATS"),
|
||||
]:
|
||||
wagtail_format_value = getattr(settings, wagtail_format, None)
|
||||
django_formats_value = getattr(settings, django_formats, None)
|
||||
for wagtail_setting, django_setting in [
|
||||
("WAGTAIL_DATE_FORMAT", "DATE_INPUT_FORMATS"),
|
||||
("WAGTAIL_DATETIME_FORMAT", "DATETIME_INPUT_FORMATS"),
|
||||
("WAGTAIL_TIME_FORMAT", "TIME_INPUT_FORMATS"),
|
||||
]:
|
||||
wagtail_format_value = getattr(settings, wagtail_setting, None)
|
||||
if wagtail_format_value is None:
|
||||
# Skip the iteration if wagtail_format is not present
|
||||
continue
|
||||
|
||||
if wagtail_format_value is None:
|
||||
# Skip the iteration if wagtail_format is not present
|
||||
continue
|
||||
|
||||
input_format = formats.get_format_lazy(wagtail_format_value)
|
||||
input_formats = formats.get_format_lazy(django_formats_value)
|
||||
if str(input_format) not in str(input_formats):
|
||||
errors.append(
|
||||
Error(
|
||||
"Configuration error",
|
||||
hint=f"{wagtail_format} {input_format} must be in {django_formats} for language {label} ({code}).",
|
||||
)
|
||||
input_formats = formats.get_format(django_setting, lang=code)
|
||||
if wagtail_format_value not in input_formats:
|
||||
errors.append(
|
||||
Error(
|
||||
"Configuration error",
|
||||
hint=f"'{wagtail_format_value}' must be in {django_setting} for language {label} ({code}).",
|
||||
obj=wagtail_setting,
|
||||
id="wagtailadmin.E003",
|
||||
)
|
||||
)
|
||||
|
||||
return errors
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
DATETIME_INPUT_FORMATS = ["%d.%m.%Y. %H:%M"]
|
|
@ -1,5 +1,6 @@
|
|||
from django.core.checks import Error
|
||||
from django.test import TestCase, override_settings
|
||||
from django.utils.formats import reset_format_cache
|
||||
|
||||
from wagtail.admin.checks import datetime_format_check
|
||||
from wagtail.test.utils import WagtailTestUtils
|
||||
|
@ -8,6 +9,9 @@ from wagtail.test.utils import WagtailTestUtils
|
|||
class TestDateTimeChecks(WagtailTestUtils, TestCase):
|
||||
fixtures = ["test.json"]
|
||||
|
||||
def setUp(self):
|
||||
reset_format_cache()
|
||||
|
||||
def test_datetime_format(self):
|
||||
with override_settings(
|
||||
WAGTAIL_CONTENT_LANGUAGES=[
|
||||
|
@ -41,7 +45,9 @@ class TestDateTimeChecks(WagtailTestUtils, TestCase):
|
|||
expected_errors = [
|
||||
Error(
|
||||
"Configuration error",
|
||||
hint="WAGTAIL_DATE_FORMAT %d.%m.%Y. must be in DATE_INPUT_FORMATS for language English (en).",
|
||||
hint="'%d.%m.%Y.' must be in DATE_INPUT_FORMATS for language English (en).",
|
||||
obj="WAGTAIL_DATE_FORMAT",
|
||||
id="wagtailadmin.E003",
|
||||
)
|
||||
]
|
||||
self.assertEqual(errors, expected_errors)
|
||||
|
@ -82,11 +88,55 @@ class TestDateTimeChecks(WagtailTestUtils, TestCase):
|
|||
expected_errors = [
|
||||
Error(
|
||||
"Configuration error",
|
||||
hint="WAGTAIL_DATETIME_FORMAT %d.%m.%Y. %H:%M must be in DATETIME_INPUT_FORMATS for language English (en).",
|
||||
hint="'%d.%m.%Y. %H:%M' must be in DATETIME_INPUT_FORMATS for language English (en).",
|
||||
obj="WAGTAIL_DATETIME_FORMAT",
|
||||
id="wagtailadmin.E003",
|
||||
),
|
||||
Error(
|
||||
"Configuration error",
|
||||
hint="WAGTAIL_TIME_FORMAT %I:%M %p must be in TIME_INPUT_FORMATS for language English (en).",
|
||||
hint="'%I:%M %p' must be in TIME_INPUT_FORMATS for language English (en).",
|
||||
obj="WAGTAIL_TIME_FORMAT",
|
||||
id="wagtailadmin.E003",
|
||||
),
|
||||
]
|
||||
self.assertEqual(errors, expected_errors)
|
||||
|
||||
def test_datetime_format_with_overriden_format(self):
|
||||
with override_settings(
|
||||
WAGTAIL_CONTENT_LANGUAGES=[
|
||||
("en", "English"),
|
||||
],
|
||||
LANGUAGES=[
|
||||
("en", "English"),
|
||||
],
|
||||
WAGTAIL_DATETIME_FORMAT="%d.%m.%Y. %H:%M",
|
||||
FORMAT_MODULE_PATH=["wagtail.admin.tests.formats"],
|
||||
USE_L10N=True,
|
||||
):
|
||||
errors = datetime_format_check(None)
|
||||
|
||||
self.assertEqual(errors, [])
|
||||
|
||||
def test_datetime_format_with_incorrect_overriden_format(self):
|
||||
with override_settings(
|
||||
WAGTAIL_CONTENT_LANGUAGES=[
|
||||
("en", "English"),
|
||||
],
|
||||
LANGUAGES=[
|
||||
("en", "English"),
|
||||
],
|
||||
WAGTAIL_DATETIME_FORMAT="%m.%d.%Y. %H:%M",
|
||||
FORMAT_MODULE_PATH=["wagtail.admin.tests.formats"],
|
||||
USE_L10N=True,
|
||||
):
|
||||
errors = datetime_format_check(None)
|
||||
|
||||
expected_errors = [
|
||||
Error(
|
||||
"Configuration error",
|
||||
hint="'%m.%d.%Y. %H:%M' must be in DATETIME_INPUT_FORMATS for language English (en).",
|
||||
obj="WAGTAIL_DATETIME_FORMAT",
|
||||
id="wagtailadmin.E003",
|
||||
),
|
||||
]
|
||||
self.assertEqual(errors, expected_errors)
|
||||
|
|
Ładowanie…
Reference in New Issue