forms.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from django.db import models
  2. from modelcluster.fields import ParentalKey
  3. from wagtail.wagtailadmin.edit_handlers import (
  4. FieldPanel,
  5. StreamFieldPanel,
  6. FieldRowPanel,
  7. InlinePanel,
  8. MultiFieldPanel)
  9. from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
  10. from wagtail.wagtailcore.fields import StreamField, RichTextField
  11. from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField
  12. from .blocks import FormPageBlock
  13. from core.models import SiteSettingsTemplateMixin
  14. class FormField(AbstractFormField):
  15. page = ParentalKey('FormPage', related_name='form_fields')
  16. class FormPage(SiteSettingsTemplateMixin, AbstractEmailForm):
  17. header_image = models.ForeignKey(
  18. 'core.OvercastImage',
  19. null=True,
  20. blank=True,
  21. on_delete=models.SET_NULL,
  22. related_name='+'
  23. )
  24. body = StreamField(FormPageBlock())
  25. thank_you_text = RichTextField(blank=True)
  26. content_panels = AbstractEmailForm.content_panels + [
  27. ImageChooserPanel('header_image'),
  28. StreamFieldPanel('body'),
  29. InlinePanel('form_fields', label="Form fields"),
  30. FieldPanel('thank_you_text', classname="full"),
  31. MultiFieldPanel([
  32. FieldRowPanel([
  33. FieldPanel('from_address', classname="col6"),
  34. FieldPanel('to_address', classname="col6"),
  35. ]),
  36. FieldPanel('subject'),
  37. ], "Email"),
  38. ]