Repository: wagtail/wagtail

Issue:
Date format in mails rendered by `EmailFormMixin` are not localized due to wrong call of  `date_format`
### Issue Summary

Dates rendered via `EmailFormMixin.render_email()` are not localized.

### Steps to Reproduce

1. Start a new project with `wagtail start myproject`
2. Edit settings to use eg. german localization

```python
LANGUAGE_CODE = "de-de"
USE_I18N = True
USE_L10N = True
```

3. [Implement form page using EmailFormMixin](https://docs.wagtail.org/en/stable/reference/contrib/forms/customisation.html#using-formmixin-or-emailformmixin-to-use-with-other-page-subclasses)
4. Create form page with date or datetime fields
5. Check notification mails send after submit and find `m/d/Y` instead of the german format `d.m.Y.`

### Fix

The bug is due to the call of `date_format` in `wagtail/contrib/forms/models.py`.

Instead of 

```python
if isinstance(value, datetime.datetime):
    value = date_format(value, settings.SHORT_DATETIME_FORMAT)
elif isinstance(value, datetime.date):
    value = date_format(value, settings.SHORT_DATE_FORMAT)
```

it should be

```python
if isinstance(value, datetime.datetime):
    value = date_format(value, "SHORT_DATETIME_FORMAT")
elif isinstance(value, datetime.date):
    value = date_format(value, "SHORT_DATE_FORMAT")
```
I guess it is quite straight forward, so I'll will open a pr soon.


Discussion:

Resolving patch:
diff --git a/wagtail/contrib/forms/models.py b/wagtail/contrib/forms/models.py
--- a/wagtail/contrib/forms/models.py
+++ b/wagtail/contrib/forms/models.py
@@ -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 @@ def render_email(self, form):
 
             # 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}")
 


Test patch:
diff --git a/wagtail/contrib/forms/tests/test_models.py b/wagtail/contrib/forms/tests/test_models.py
--- a/wagtail/contrib/forms/tests/test_models.py
+++ b/wagtail/contrib/forms/tests/test_models.py
@@ -770,6 +770,32 @@ def test_datetime_normalization(self):
         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"]