kopia lustrzana https://github.com/wagtail/wagtail
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 #11696pull/11714/head
rodzic
28f42bd6a6
commit
c580342a95
|
@ -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: 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 local development of docs when running `make livehtml` (Sage Abdullah)
|
||||||
* Fix: Resolve issue with unwanted padding in chooser modal listings (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: 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: 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)
|
* Docs: Update content and page names to their US spelling instead of UK spelling (Victoria Poromon)
|
||||||
|
|
|
@ -805,6 +805,7 @@
|
||||||
* Viktor Szépe
|
* Viktor Szépe
|
||||||
* Pranith Beeram
|
* Pranith Beeram
|
||||||
* Maranda Provance
|
* Maranda Provance
|
||||||
|
* Mark Niehues
|
||||||
|
|
||||||
## Translators
|
## Translators
|
||||||
|
|
||||||
|
|
|
@ -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)
|
* 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 local development of docs when running `make livehtml` (Sage Abdullah)
|
||||||
* Resolve issue with unwanted padding in chooser modal listings (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
|
### Documentation
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.core.serializers.json import DjangoJSONEncoder
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
from django.core.validators import validate_email
|
from django.core.validators import validate_email
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -365,9 +364,9 @@ class EmailFormMixin(models.Model):
|
||||||
|
|
||||||
# Format dates and datetime(s) with SHORT_DATE(TIME)_FORMAT
|
# Format dates and datetime(s) with SHORT_DATE(TIME)_FORMAT
|
||||||
if isinstance(value, datetime.datetime):
|
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):
|
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}")
|
content.append(f"{field.label}: {value}")
|
||||||
|
|
||||||
|
|
|
@ -770,6 +770,32 @@ class TestCleanedDataEmails(TestCase):
|
||||||
self.assertEqual(len(mail.outbox), 3)
|
self.assertEqual(len(mail.outbox), 3)
|
||||||
self.assertIn("Datetime: 12/21/1910 9:19 p.m.", mail.outbox[2].body)
|
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):
|
class TestIssue798(WagtailTestUtils, TestCase):
|
||||||
fixtures = ["test.json"]
|
fixtures = ["test.json"]
|
||||||
|
|
Ładowanie…
Reference in New Issue