We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Formbuilder number fields do not work in 0.8
Steps to reproduce:

1) Create a form and give it a field type set to 'number'.
2) Submit the form with a number in the number field.

Result:

`Traceback (most recent call last):
  File "/usr/local/django/virtualenvs/bhfnsdwagtail/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/django/virtualenvs/bhfnsdwagtail/local/lib/python2.7/site-packages/wagtail/wagtailcore/views.py", line 27, in serve
    return page.serve(request, *args, **kwargs)
  File "/usr/local/django/virtualenvs/bhfnsdwagtail/local/lib/python2.7/site-packages/wagtail/wagtailforms/models.py", line 148, in serve
    self.process_form_submission(form)
  File "/usr/local/django/virtualenvs/bhfnsdwagtail/local/lib/python2.7/site-packages/wagtail/wagtailforms/models.py", line 190, in process_form_submission
    super(AbstractEmailForm, self).process_form_submission(form)
  File "/usr/local/django/virtualenvs/bhfnsdwagtail/local/lib/python2.7/site-packages/wagtail/wagtailforms/models.py", line 135, in process_form_submission
    form_data=json.dumps(form.cleaned_data),
  File "/usr/lib/python2.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/json/encoder.py", line 263, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python2.7/json/encoder.py", line 177, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: Decimal('5421515526') is not JSON serializable`


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `wagtail/wagtailforms/models.py`
Content:
```
1 import json
2 import re
3 
4 from six import text_type
5 
6 from unidecode import unidecode
7 
8 from django.db import models
9 from django.shortcuts import render
10 from django.utils.translation import ugettext_lazy as _
11 from django.utils.text import slugify
12 from django.utils.encoding import python_2_unicode_compatible
13 
14 from wagtail.wagtailcore.models import Page, Orderable, UserPagePermissionsProxy, get_page_types
15 from wagtail.wagtailadmin.edit_handlers import FieldPanel
16 from wagtail.wagtailadmin import tasks
17 
18 from .forms import FormBuilder
19 
20 
21 FORM_FIELD_CHOICES = (
22     ('singleline',   _('Single line text')),
23     ('multiline',    _('Multi-line text')),
24     ('email',        _('Email')),
25     ('number',       _('Number')),
26     ('url',          _('URL')),
27     ('checkbox',     _('Checkbox')),
28     ('checkboxes',   _('Checkboxes')),
29     ('dropdown',     _('Drop down')),
30     ('radio',        _('Radio buttons')),
31     ('date',         _('Date')),
32     ('datetime',     _('Date/time')),
33 )
34 
35 
36 HTML_EXTENSION_RE = re.compile(r"(.*)\.html")
37 
38 
39 @python_2_unicode_compatible
40 class FormSubmission(models.Model):
41     """Data for a Form submission."""
42 
43     form_data = models.TextField()
44     page = models.ForeignKey(Page)
45 
46     submit_time = models.DateTimeField(auto_now_add=True)
47 
48     def get_data(self):
49         return json.loads(self.form_data)
50 
51     def __str__(self):
52         return self.form_data
53 
54 
55 class AbstractFormField(Orderable):
56     """Database Fields required for building a Django Form field."""
57 
58     label = models.CharField(
59         max_length=255,
60         help_text=_('The label of the form field')
61     )
62     field_type = models.CharField(max_length=16, choices=FORM_FIELD_CHOICES)
63     required = models.BooleanField(default=True)
64     choices = models.CharField(
65         max_length=512,
66         blank=True,
67         help_text=_('Comma separated list of choices. Only applicable in checkboxes, radio and dropdown.')
68     )
69     default_value = models.CharField(
70         max_length=255,
71         blank=True,
72         help_text=_('Default value. Comma separated values supported for checkboxes.')
73     )
74     help_text = models.CharField(max_length=255, blank=True)
75 
76     @property
77     def clean_name(self):
78         # unidecode will return an ascii string while slugify wants a
79         # unicode string on the other hand, slugify returns a safe-string
80         # which will be converted to a normal str
81         return str(slugify(text_type(unidecode(self.label))))
82 
83     panels = [
84         FieldPanel('label'),
85         FieldPanel('help_text'),
86         FieldPanel('required'),
87         FieldPanel('field_type', classname="formbuilder-type"),
88         FieldPanel('choices', classname="formbuilder-choices"),
89         FieldPanel('default_value', classname="formbuilder-default"),
90     ]
91 
92     class Meta:
93         abstract = True
94         ordering = ['sort_order']
95 
96 
97 _FORM_CONTENT_TYPES = None
98 
99 def get_form_types():
100     global _FORM_CONTENT_TYPES
101     if _FORM_CONTENT_TYPES is None:
102         _FORM_CONTENT_TYPES = [
103             ct for ct in get_page_types()
104             if issubclass(ct.model_class(), AbstractForm)
105         ]
106     return _FORM_CONTENT_TYPES
107 
108 
109 def get_forms_for_user(user):
110     """Return a queryset of form pages that this user is allowed to access the submissions for"""
111     editable_pages = UserPagePermissionsProxy(user).editable_pages()
112     return editable_pages.filter(content_type__in=get_form_types())
113 
114 
115 class AbstractForm(Page):
116     """A Form Page. Pages implementing a form should inhert from it"""
117 
118     form_builder = FormBuilder
119     is_abstract = True  # Don't display me in "Add"
120 
121     def __init__(self, *args, **kwargs):
122         super(AbstractForm, self).__init__(*args, **kwargs)
123         if not hasattr(self, 'landing_page_template'):
124             template_wo_ext = re.match(HTML_EXTENSION_RE, self.template).group(1)
125             self.landing_page_template = template_wo_ext + '_landing.html'
126 
127     class Meta:
128         abstract = True
129 
130     def get_form_parameters(self):
131         return {}
132 
133     def process_form_submission(self, form):
134         FormSubmission.objects.create(
135             form_data=json.dumps(form.cleaned_data),
136             page=self,
137         )
138 
139     def serve(self, request):
140         fb = self.form_builder(self.form_fields.all())
141         form_class = fb.get_form_class()
142         form_params = self.get_form_parameters()
143 
144         if request.method == 'POST':
145             form = form_class(request.POST, **form_params)
146 
147             if form.is_valid():
148                 self.process_form_submission(form)
149                 # If we have a form_processing_backend call its process method
150                 if hasattr(self, 'form_processing_backend'):
151                     form_processor = self.form_processing_backend()
152                     form_processor.process(self, form)
153 
154                 # render the landing_page
155                 # TODO: It is much better to redirect to it
156                 return render(request, self.landing_page_template, {
157                     'self': self,
158                 })
159         else:
160             form = form_class(**form_params)
161 
162         return render(request, self.template, {
163             'self': self,
164             'form': form,
165         })
166 
167     preview_modes = [
168         ('form', 'Form'),
169         ('landing', 'Landing page'),
170     ]
171 
172     def serve_preview(self, request, mode):
173         if mode == 'landing':
174             return render(request, self.landing_page_template, {
175                 'self': self,
176             })
177         else:
178             return super(AbstractForm, self).serve_preview(request, mode)
179 
180 
181 class AbstractEmailForm(AbstractForm):
182     """A Form Page that sends email. Pages implementing a form to be send to an email should inherit from it"""
183     is_abstract = True  # Don't display me in "Add"
184 
185     to_address = models.CharField(max_length=255, blank=True, help_text=_("Optional - form submissions will be emailed to this address"))
186     from_address = models.CharField(max_length=255, blank=True)
187     subject = models.CharField(max_length=255, blank=True)
188 
189     def process_form_submission(self, form):
190         super(AbstractEmailForm, self).process_form_submission(form)
191 
192         if self.to_address:
193             content = '\n'.join([x[1].label + ': ' + form.data.get(x[0]) for x in form.fields.items()])
194             tasks.send_email_task.delay(self.subject, content, [self.to_address], self.from_address,)
195 
196 
197     class Meta:
198         abstract = True
199
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/wagtail/wagtailforms/models.py b/wagtail/wagtailforms/models.py
--- a/wagtail/wagtailforms/models.py
+++ b/wagtail/wagtailforms/models.py
@@ -10,6 +10,7 @@
 from django.utils.translation import ugettext_lazy as _
 from django.utils.text import slugify
 from django.utils.encoding import python_2_unicode_compatible
+from django.core.serializers.json import DjangoJSONEncoder
 
 from wagtail.wagtailcore.models import Page, Orderable, UserPagePermissionsProxy, get_page_types
 from wagtail.wagtailadmin.edit_handlers import FieldPanel
@@ -132,7 +133,7 @@
 
     def process_form_submission(self, form):
         FormSubmission.objects.create(
-            form_data=json.dumps(form.cleaned_data),
+            form_data=json.dumps(form.cleaned_data, cls=DjangoJSONEncoder),
             page=self,
         )

{"golden_diff": "diff --git a/wagtail/wagtailforms/models.py b/wagtail/wagtailforms/models.py\n--- a/wagtail/wagtailforms/models.py\n+++ b/wagtail/wagtailforms/models.py\n@@ -10,6 +10,7 @@\n from django.utils.translation import ugettext_lazy as _\n from django.utils.text import slugify\n from django.utils.encoding import python_2_unicode_compatible\n+from django.core.serializers.json import DjangoJSONEncoder\n \n from wagtail.wagtailcore.models import Page, Orderable, UserPagePermissionsProxy, get_page_types\n from wagtail.wagtailadmin.edit_handlers import FieldPanel\n@@ -132,7 +133,7 @@\n \n     def process_form_submission(self, form):\n         FormSubmission.objects.create(\n-            form_data=json.dumps(form.cleaned_data),\n+            form_data=json.dumps(form.cleaned_data, cls=DjangoJSONEncoder),\n             page=self,\n         )\n", "issue": "Formbuilder number fields do not work in 0.8\nSteps to reproduce:\n\n1) Create a form and give it a field type set to 'number'.\n2) Submit the form with a number in the number field.\n\nResult:\n\n`Traceback (most recent call last):\n  File \"/usr/local/django/virtualenvs/bhfnsdwagtail/local/lib/python2.7/site-packages/django/core/handlers/base.py\", line 111, in get_response\n    response = wrapped_callback(request, *callback_args, **callback_kwargs)\n  File \"/usr/local/django/virtualenvs/bhfnsdwagtail/local/lib/python2.7/site-packages/wagtail/wagtailcore/views.py\", line 27, in serve\n    return page.serve(request, *args, **kwargs)\n  File \"/usr/local/django/virtualenvs/bhfnsdwagtail/local/lib/python2.7/site-packages/wagtail/wagtailforms/models.py\", line 148, in serve\n    self.process_form_submission(form)\n  File \"/usr/local/django/virtualenvs/bhfnsdwagtail/local/lib/python2.7/site-packages/wagtail/wagtailforms/models.py\", line 190, in process_form_submission\n    super(AbstractEmailForm, self).process_form_submission(form)\n  File \"/usr/local/django/virtualenvs/bhfnsdwagtail/local/lib/python2.7/site-packages/wagtail/wagtailforms/models.py\", line 135, in process_form_submission\n    form_data=json.dumps(form.cleaned_data),\n  File \"/usr/lib/python2.7/json/__init__.py\", line 231, in dumps\n    return _default_encoder.encode(obj)\n  File \"/usr/lib/python2.7/json/encoder.py\", line 200, in encode\n    chunks = self.iterencode(o, _one_shot=True)\n  File \"/usr/lib/python2.7/json/encoder.py\", line 263, in iterencode\n    return _iterencode(o, 0)\n  File \"/usr/lib/python2.7/json/encoder.py\", line 177, in default\n    raise TypeError(repr(o) + \" is not JSON serializable\")\nTypeError: Decimal('5421515526') is not JSON serializable`\n\n", "before_files": [{"content": "import json\nimport re\n\nfrom six import text_type\n\nfrom unidecode import unidecode\n\nfrom django.db import models\nfrom django.shortcuts import render\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.utils.text import slugify\nfrom django.utils.encoding import python_2_unicode_compatible\n\nfrom wagtail.wagtailcore.models import Page, Orderable, UserPagePermissionsProxy, get_page_types\nfrom wagtail.wagtailadmin.edit_handlers import FieldPanel\nfrom wagtail.wagtailadmin import tasks\n\nfrom .forms import FormBuilder\n\n\nFORM_FIELD_CHOICES = (\n    ('singleline',   _('Single line text')),\n    ('multiline',    _('Multi-line text')),\n    ('email',        _('Email')),\n    ('number',       _('Number')),\n    ('url',          _('URL')),\n    ('checkbox',     _('Checkbox')),\n    ('checkboxes',   _('Checkboxes')),\n    ('dropdown',     _('Drop down')),\n    ('radio',        _('Radio buttons')),\n    ('date',         _('Date')),\n    ('datetime',     _('Date/time')),\n)\n\n\nHTML_EXTENSION_RE = re.compile(r\"(.*)\\.html\")\n\n\n@python_2_unicode_compatible\nclass FormSubmission(models.Model):\n    \"\"\"Data for a Form submission.\"\"\"\n\n    form_data = models.TextField()\n    page = models.ForeignKey(Page)\n\n    submit_time = models.DateTimeField(auto_now_add=True)\n\n    def get_data(self):\n        return json.loads(self.form_data)\n\n    def __str__(self):\n        return self.form_data\n\n\nclass AbstractFormField(Orderable):\n    \"\"\"Database Fields required for building a Django Form field.\"\"\"\n\n    label = models.CharField(\n        max_length=255,\n        help_text=_('The label of the form field')\n    )\n    field_type = models.CharField(max_length=16, choices=FORM_FIELD_CHOICES)\n    required = models.BooleanField(default=True)\n    choices = models.CharField(\n        max_length=512,\n        blank=True,\n        help_text=_('Comma separated list of choices. Only applicable in checkboxes, radio and dropdown.')\n    )\n    default_value = models.CharField(\n        max_length=255,\n        blank=True,\n        help_text=_('Default value. Comma separated values supported for checkboxes.')\n    )\n    help_text = models.CharField(max_length=255, blank=True)\n\n    @property\n    def clean_name(self):\n        # unidecode will return an ascii string while slugify wants a\n        # unicode string on the other hand, slugify returns a safe-string\n        # which will be converted to a normal str\n        return str(slugify(text_type(unidecode(self.label))))\n\n    panels = [\n        FieldPanel('label'),\n        FieldPanel('help_text'),\n        FieldPanel('required'),\n        FieldPanel('field_type', classname=\"formbuilder-type\"),\n        FieldPanel('choices', classname=\"formbuilder-choices\"),\n        FieldPanel('default_value', classname=\"formbuilder-default\"),\n    ]\n\n    class Meta:\n        abstract = True\n        ordering = ['sort_order']\n\n\n_FORM_CONTENT_TYPES = None\n\ndef get_form_types():\n    global _FORM_CONTENT_TYPES\n    if _FORM_CONTENT_TYPES is None:\n        _FORM_CONTENT_TYPES = [\n            ct for ct in get_page_types()\n            if issubclass(ct.model_class(), AbstractForm)\n        ]\n    return _FORM_CONTENT_TYPES\n\n\ndef get_forms_for_user(user):\n    \"\"\"Return a queryset of form pages that this user is allowed to access the submissions for\"\"\"\n    editable_pages = UserPagePermissionsProxy(user).editable_pages()\n    return editable_pages.filter(content_type__in=get_form_types())\n\n\nclass AbstractForm(Page):\n    \"\"\"A Form Page. Pages implementing a form should inhert from it\"\"\"\n\n    form_builder = FormBuilder\n    is_abstract = True  # Don't display me in \"Add\"\n\n    def __init__(self, *args, **kwargs):\n        super(AbstractForm, self).__init__(*args, **kwargs)\n        if not hasattr(self, 'landing_page_template'):\n            template_wo_ext = re.match(HTML_EXTENSION_RE, self.template).group(1)\n            self.landing_page_template = template_wo_ext + '_landing.html'\n\n    class Meta:\n        abstract = True\n\n    def get_form_parameters(self):\n        return {}\n\n    def process_form_submission(self, form):\n        FormSubmission.objects.create(\n            form_data=json.dumps(form.cleaned_data),\n            page=self,\n        )\n\n    def serve(self, request):\n        fb = self.form_builder(self.form_fields.all())\n        form_class = fb.get_form_class()\n        form_params = self.get_form_parameters()\n\n        if request.method == 'POST':\n            form = form_class(request.POST, **form_params)\n\n            if form.is_valid():\n                self.process_form_submission(form)\n                # If we have a form_processing_backend call its process method\n                if hasattr(self, 'form_processing_backend'):\n                    form_processor = self.form_processing_backend()\n                    form_processor.process(self, form)\n\n                # render the landing_page\n                # TODO: It is much better to redirect to it\n                return render(request, self.landing_page_template, {\n                    'self': self,\n                })\n        else:\n            form = form_class(**form_params)\n\n        return render(request, self.template, {\n            'self': self,\n            'form': form,\n        })\n\n    preview_modes = [\n        ('form', 'Form'),\n        ('landing', 'Landing page'),\n    ]\n\n    def serve_preview(self, request, mode):\n        if mode == 'landing':\n            return render(request, self.landing_page_template, {\n                'self': self,\n            })\n        else:\n            return super(AbstractForm, self).serve_preview(request, mode)\n\n\nclass AbstractEmailForm(AbstractForm):\n    \"\"\"A Form Page that sends email. Pages implementing a form to be send to an email should inherit from it\"\"\"\n    is_abstract = True  # Don't display me in \"Add\"\n\n    to_address = models.CharField(max_length=255, blank=True, help_text=_(\"Optional - form submissions will be emailed to this address\"))\n    from_address = models.CharField(max_length=255, blank=True)\n    subject = models.CharField(max_length=255, blank=True)\n\n    def process_form_submission(self, form):\n        super(AbstractEmailForm, self).process_form_submission(form)\n\n        if self.to_address:\n            content = '\\n'.join([x[1].label + ': ' + form.data.get(x[0]) for x in form.fields.items()])\n            tasks.send_email_task.delay(self.subject, content, [self.to_address], self.from_address,)\n\n\n    class Meta:\n        abstract = True\n", "path": "wagtail/wagtailforms/models.py"}], "after_files": [{"content": "import json\nimport re\n\nfrom six import text_type\n\nfrom unidecode import unidecode\n\nfrom django.db import models\nfrom django.shortcuts import render\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.utils.text import slugify\nfrom django.utils.encoding import python_2_unicode_compatible\nfrom django.core.serializers.json import DjangoJSONEncoder\n\nfrom wagtail.wagtailcore.models import Page, Orderable, UserPagePermissionsProxy, get_page_types\nfrom wagtail.wagtailadmin.edit_handlers import FieldPanel\nfrom wagtail.wagtailadmin import tasks\n\nfrom .forms import FormBuilder\n\n\nFORM_FIELD_CHOICES = (\n    ('singleline',   _('Single line text')),\n    ('multiline',    _('Multi-line text')),\n    ('email',        _('Email')),\n    ('number',       _('Number')),\n    ('url',          _('URL')),\n    ('checkbox',     _('Checkbox')),\n    ('checkboxes',   _('Checkboxes')),\n    ('dropdown',     _('Drop down')),\n    ('radio',        _('Radio buttons')),\n    ('date',         _('Date')),\n    ('datetime',     _('Date/time')),\n)\n\n\nHTML_EXTENSION_RE = re.compile(r\"(.*)\\.html\")\n\n\n@python_2_unicode_compatible\nclass FormSubmission(models.Model):\n    \"\"\"Data for a Form submission.\"\"\"\n\n    form_data = models.TextField()\n    page = models.ForeignKey(Page)\n\n    submit_time = models.DateTimeField(auto_now_add=True)\n\n    def get_data(self):\n        return json.loads(self.form_data)\n\n    def __str__(self):\n        return self.form_data\n\n\nclass AbstractFormField(Orderable):\n    \"\"\"Database Fields required for building a Django Form field.\"\"\"\n\n    label = models.CharField(\n        max_length=255,\n        help_text=_('The label of the form field')\n    )\n    field_type = models.CharField(max_length=16, choices=FORM_FIELD_CHOICES)\n    required = models.BooleanField(default=True)\n    choices = models.CharField(\n        max_length=512,\n        blank=True,\n        help_text=_('Comma separated list of choices. Only applicable in checkboxes, radio and dropdown.')\n    )\n    default_value = models.CharField(\n        max_length=255,\n        blank=True,\n        help_text=_('Default value. Comma separated values supported for checkboxes.')\n    )\n    help_text = models.CharField(max_length=255, blank=True)\n\n    @property\n    def clean_name(self):\n        # unidecode will return an ascii string while slugify wants a\n        # unicode string on the other hand, slugify returns a safe-string\n        # which will be converted to a normal str\n        return str(slugify(text_type(unidecode(self.label))))\n\n    panels = [\n        FieldPanel('label'),\n        FieldPanel('help_text'),\n        FieldPanel('required'),\n        FieldPanel('field_type', classname=\"formbuilder-type\"),\n        FieldPanel('choices', classname=\"formbuilder-choices\"),\n        FieldPanel('default_value', classname=\"formbuilder-default\"),\n    ]\n\n    class Meta:\n        abstract = True\n        ordering = ['sort_order']\n\n\n_FORM_CONTENT_TYPES = None\n\ndef get_form_types():\n    global _FORM_CONTENT_TYPES\n    if _FORM_CONTENT_TYPES is None:\n        _FORM_CONTENT_TYPES = [\n            ct for ct in get_page_types()\n            if issubclass(ct.model_class(), AbstractForm)\n        ]\n    return _FORM_CONTENT_TYPES\n\n\ndef get_forms_for_user(user):\n    \"\"\"Return a queryset of form pages that this user is allowed to access the submissions for\"\"\"\n    editable_pages = UserPagePermissionsProxy(user).editable_pages()\n    return editable_pages.filter(content_type__in=get_form_types())\n\n\nclass AbstractForm(Page):\n    \"\"\"A Form Page. Pages implementing a form should inhert from it\"\"\"\n\n    form_builder = FormBuilder\n    is_abstract = True  # Don't display me in \"Add\"\n\n    def __init__(self, *args, **kwargs):\n        super(AbstractForm, self).__init__(*args, **kwargs)\n        if not hasattr(self, 'landing_page_template'):\n            template_wo_ext = re.match(HTML_EXTENSION_RE, self.template).group(1)\n            self.landing_page_template = template_wo_ext + '_landing.html'\n\n    class Meta:\n        abstract = True\n\n    def get_form_parameters(self):\n        return {}\n\n    def process_form_submission(self, form):\n        FormSubmission.objects.create(\n            form_data=json.dumps(form.cleaned_data, cls=DjangoJSONEncoder),\n            page=self,\n        )\n\n    def serve(self, request):\n        fb = self.form_builder(self.form_fields.all())\n        form_class = fb.get_form_class()\n        form_params = self.get_form_parameters()\n\n        if request.method == 'POST':\n            form = form_class(request.POST, **form_params)\n\n            if form.is_valid():\n                self.process_form_submission(form)\n                # If we have a form_processing_backend call its process method\n                if hasattr(self, 'form_processing_backend'):\n                    form_processor = self.form_processing_backend()\n                    form_processor.process(self, form)\n\n                # render the landing_page\n                # TODO: It is much better to redirect to it\n                return render(request, self.landing_page_template, {\n                    'self': self,\n                })\n        else:\n            form = form_class(**form_params)\n\n        return render(request, self.template, {\n            'self': self,\n            'form': form,\n        })\n\n    preview_modes = [\n        ('form', 'Form'),\n        ('landing', 'Landing page'),\n    ]\n\n    def serve_preview(self, request, mode):\n        if mode == 'landing':\n            return render(request, self.landing_page_template, {\n                'self': self,\n            })\n        else:\n            return super(AbstractForm, self).serve_preview(request, mode)\n\n\nclass AbstractEmailForm(AbstractForm):\n    \"\"\"A Form Page that sends email. Pages implementing a form to be send to an email should inherit from it\"\"\"\n    is_abstract = True  # Don't display me in \"Add\"\n\n    to_address = models.CharField(max_length=255, blank=True, help_text=_(\"Optional - form submissions will be emailed to this address\"))\n    from_address = models.CharField(max_length=255, blank=True)\n    subject = models.CharField(max_length=255, blank=True)\n\n    def process_form_submission(self, form):\n        super(AbstractEmailForm, self).process_form_submission(form)\n\n        if self.to_address:\n            content = '\\n'.join([x[1].label + ': ' + form.data.get(x[0]) for x in form.fields.items()])\n            tasks.send_email_task.delay(self.subject, content, [self.to_address], self.from_address,)\n\n\n    class Meta:\n        abstract = True\n", "path": "wagtail/wagtailforms/models.py"}]}