Fix date formatting in form builder email content

Ensure that the date_format util correctly gets passed a format reference, not the resolved format.
Fixes #11696
pull/11714/head
Mark Niehues 2024-02-26 15:21:32 +01:00 zatwierdzone przez LB (Ben Johnston)
rodzic 28f42bd6a6
commit c580342a95
5 zmienionych plików z 31 dodań i 3 usunięć

Wyświetl plik

@ -21,6 +21,7 @@ Changelog
* Fix: Consistently remove model's `verbose_name` in group edit view when listing custom permissions (Sage Abdullah, Neeraj Yetheendran, Omkar Jadhav)
* Fix: Resolve issue local development of docs when running `make livehtml` (Sage Abdullah)
* Fix: Resolve issue with unwanted padding in chooser modal listings (Sage Abdullah)
* Fix: Ensure form builder emails that have date or datetime fields correctly localize dates based on the configured `LANGUAGE_CODE` (Mark Niehues)
* Docs: Add contributing development documentation on how to work with a fork of Wagtail (Nix Asteri, Dan Braghis)
* Docs: Make sure the settings panel is listed in tabbed interface examples (Tibor Leupold)
* Docs: Update content and page names to their US spelling instead of UK spelling (Victoria Poromon)

Wyświetl plik

@ -805,6 +805,7 @@
* Viktor Szépe
* Pranith Beeram
* Maranda Provance
* Mark Niehues
## Translators

Wyświetl plik

@ -34,6 +34,7 @@ depth: 1
* Consistently remove model's `verbose_name` in group edit view when listing custom permissions (Sage Abdullah, Neeraj Yetheendran, Omkar Jadhav)
* Resolve issue local development of docs when running `make livehtml` (Sage Abdullah)
* Resolve issue with unwanted padding in chooser modal listings (Sage Abdullah)
* Ensure form builder emails that have date or datetime fields correctly localize dates based on the configured `LANGUAGE_CODE` (Mark Niehues)
### Documentation

Wyświetl plik

@ -1,7 +1,6 @@
import datetime
import os
from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder
from django.core.validators import validate_email
from django.db import models
@ -365,9 +364,9 @@ class EmailFormMixin(models.Model):
# Format dates and datetime(s) with SHORT_DATE(TIME)_FORMAT
if isinstance(value, datetime.datetime):
value = date_format(value, settings.SHORT_DATETIME_FORMAT)
value = date_format(value, "SHORT_DATETIME_FORMAT")
elif isinstance(value, datetime.date):
value = date_format(value, settings.SHORT_DATE_FORMAT)
value = date_format(value, "SHORT_DATE_FORMAT")
content.append(f"{field.label}: {value}")

Wyświetl plik

@ -770,6 +770,32 @@ class TestCleanedDataEmails(TestCase):
self.assertEqual(len(mail.outbox), 3)
self.assertIn("Datetime: 12/21/1910 9:19 p.m.", mail.outbox[2].body)
@override_settings(USE_I18N=True, LANGUAGE_CODE="de")
def test_date_localization(self):
self.client.post(
"/contact-us/",
{
"date": "2017-12-31",
},
)
# Check the email
self.assertEqual(len(mail.outbox), 1)
self.assertIn("Date: 31.12.2017", mail.outbox[0].body)
@override_settings(USE_I18N=True, LANGUAGE_CODE="de")
def test_datetime_localization(self):
self.client.post(
"/contact-us/",
{
"datetime": "1910-12-21 21:19:12",
},
)
# Check the email
self.assertEqual(len(mail.outbox), 1)
self.assertIn("Datetime: 21.12.1910 21:19", mail.outbox[0].body)
class TestIssue798(WagtailTestUtils, TestCase):
fixtures = ["test.json"]