Skip to content

Commit

Permalink
Moved send_mail logic to seperate method to simplify overriding just …
Browse files Browse the repository at this point in the history
…this part of the form process
  • Loading branch information
tleguijt authored and m1kola committed Aug 26, 2016
1 parent c40ab35 commit 2403be5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions wagtail/wagtailforms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_form(self, *args, **kwargs):
return form_class(*args, **form_params)

def process_form_submission(self, form):
FormSubmission.objects.create(
return FormSubmission.objects.create(
form_data=json.dumps(form.cleaned_data, cls=DjangoJSONEncoder),
page=self,
)
Expand Down Expand Up @@ -216,12 +216,15 @@ class AbstractEmailForm(AbstractForm):
subject = models.CharField(verbose_name=_('subject'), max_length=255, blank=True)

def process_form_submission(self, form):
super(AbstractEmailForm, self).process_form_submission(form)

submission = 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, addresses, self.from_address,)
self.send_form_mail(form)
return submission

def send_form_mail(self, form):
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, addresses, self.from_address,)

class Meta:
abstract = True

0 comments on commit 2403be5

Please sign in to comment.