kopia lustrzana https://github.com/wagtail/wagtail
Allow multiple, comma seperated email addresses...
to be used in the `to_address field` in the `AbstractEmailForm`.pull/2821/head
rodzic
9961455c6a
commit
16953c79f3
|
@ -19,6 +19,7 @@ Changelog
|
|||
* Wagtail version number is now shown on the settings menu (Chris Rogers)
|
||||
* Added a system check to validate that fields listed in `search_fields` are defined on the model (Josh Schneier)
|
||||
* Added formal APIs for customising the display of StructBlock forms within the page editor (Matt Westcott)
|
||||
* `wagtailforms.models.AbstractEmailForm` now supports multiple email recipients (Serafeim Papastefanos)
|
||||
* Fix: Email templates and document uploader now support custom `STATICFILES_STORAGE` (Jonny Scholes)
|
||||
* Fix: Removed alignment options (deprecated in HTML and not rendered by Wagtail) from `TableBlock` context menu (Moritz Pfeiffer)
|
||||
* Fix: Fixed incorrect CSS path on ModelAdmin's "choose a parent page" view
|
||||
|
|
|
@ -34,6 +34,7 @@ Minor features
|
|||
* Wagtail version number is now shown on the settings menu (Chris Rogers)
|
||||
* Added a system check to validate that fields listed in ``search_fields`` are defined on the model (Josh Schneier)
|
||||
* Added formal APIs for customising the display of StructBlock forms within the page editor - see :ref:`custom_editing_interfaces_for_structblock` (Matt Westcott)
|
||||
* ``wagtailforms.models.AbstractEmailForm`` now supports multiple email recipients (Serafeim Papastefanos)
|
||||
|
||||
|
||||
Bug fixes
|
||||
|
|
|
@ -293,7 +293,7 @@ class Migration(migrations.Migration):
|
|||
name='FormPage',
|
||||
fields=[
|
||||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
|
||||
('to_address', models.CharField(blank=True, help_text='Optional - form submissions will be emailed to this address', max_length=255, verbose_name='to address')),
|
||||
('to_address', models.CharField(blank=True, help_text='Optional - form submissions will be emailed to these addresses. Separate multiple addresses by comma.', max_length=255, verbose_name='to address')),
|
||||
('from_address', models.CharField(blank=True, max_length=255, verbose_name='from address')),
|
||||
('subject', models.CharField(blank=True, max_length=255, verbose_name='subject')),
|
||||
],
|
||||
|
|
|
@ -210,7 +210,7 @@ class AbstractEmailForm(AbstractForm):
|
|||
|
||||
to_address = models.CharField(
|
||||
verbose_name=_('to address'), max_length=255, blank=True,
|
||||
help_text=_("Optional - form submissions will be emailed to this address")
|
||||
help_text=_("Optional - form submissions will be emailed to these addresses. Separate multiple addresses by comma.")
|
||||
)
|
||||
from_address = models.CharField(verbose_name=_('from address'), max_length=255, blank=True)
|
||||
subject = models.CharField(verbose_name=_('subject'), max_length=255, blank=True)
|
||||
|
@ -219,8 +219,9 @@ class AbstractEmailForm(AbstractForm):
|
|||
super(AbstractEmailForm, self).process_form_submission(form)
|
||||
|
||||
if self.to_address:
|
||||
addresses = [x.strip() for x in self.to_address.split(',')]
|
||||
content = '\n'.join([x[1].label + ': ' + text_type(form.data.get(x[0])) for x in form.fields.items()])
|
||||
send_mail(self.subject, content, [self.to_address], self.from_address,)
|
||||
send_mail(self.subject, content, addresses, self.from_address,)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
|
|
@ -159,6 +159,39 @@ class TestFormSubmission(TestCase):
|
|||
self.assertIn("Your choices: None", mail.outbox[0].body)
|
||||
|
||||
|
||||
class TestFormSubmissionWithMultipleRecipients(TestCase):
|
||||
def setUp(self):
|
||||
# Create a form page
|
||||
self.form_page = make_form_page(to_address='to@email.com, another@email.com')
|
||||
|
||||
def test_post_valid_form(self):
|
||||
response = self.client.post('/contact-us/', {
|
||||
'your-email': 'bob@example.com',
|
||||
'your-message': 'hello world',
|
||||
'your-choices': {'foo': '', 'bar': '', 'baz': ''}
|
||||
})
|
||||
|
||||
# Check response
|
||||
self.assertContains(response, "Thank you for your feedback.")
|
||||
self.assertTemplateNotUsed(response, 'tests/form_page.html')
|
||||
self.assertTemplateUsed(response, 'tests/form_page_landing.html')
|
||||
|
||||
# check that variables defined in get_context are passed through to the template (#1429)
|
||||
self.assertContains(response, "<p>hello world</p>")
|
||||
|
||||
# Check that one email was sent, but to two recipients
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
|
||||
self.assertEqual(mail.outbox[0].subject, "The subject")
|
||||
self.assertIn("Your message: hello world", mail.outbox[0].body)
|
||||
self.assertEqual(mail.outbox[0].from_email, 'from@email.com')
|
||||
self.assertEqual(set(mail.outbox[0].to), {'to@email.com', 'another@email.com'})
|
||||
|
||||
# Check that form submission was saved correctly
|
||||
form_page = Page.objects.get(url_path='/home/contact-us/')
|
||||
self.assertTrue(FormSubmission.objects.filter(page=form_page, form_data__contains='hello world').exists())
|
||||
|
||||
|
||||
class TestFormBuilder(TestCase):
|
||||
def setUp(self):
|
||||
# Create a form page
|
||||
|
|
Ładowanie…
Reference in New Issue