示例#1
0
    def setUp(self):
        self.form_page = make_form_page()

        self.FormPageForm = get_form_for_model(FormPage,
                                               form_class=WagtailAdminPageForm)

        submissions_panel = FormSubmissionsPanel().bind_to_model(FormPage)

        self.panel = submissions_panel(self.form_page, self.FormPageForm())
示例#2
0
class ContactPage(AbstractEmailForm):
    intro = RichTextField(blank=True)
    thank_you_text = RichTextField(blank=True)
    body = StreamField([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('image', ImageChooserBlock()),
        ('blockquote', blocks.BlockQuoteBlock()),
        ('raw_html', blocks.RawHTMLBlock()),
    ], blank=True)

    content_panels = AbstractEmailForm.content_panels + [
        FormSubmissionsPanel(),
        FieldPanel('intro', classname="full"),
        InlinePanel('contact_fields', label="Form fields"),
        StreamFieldPanel('body'),
        FieldPanel('thank_you_text', classname="full"),
        MultiFieldPanel([
            FieldRowPanel([
                FieldPanel('from_address', classname="col6"),
                FieldPanel('to_address', classname="col6"),
            ]),
            FieldPanel('subject'),
        ], "Email"),
    ]

    def get_form_fields(self):
        return self.contact_fields.all()

    def send_mail(self, form):
        # Overwrite the send_mail method from AbstractEmailForm
        # to use inquiry as email subject.
        addresses = [x.strip() for x in self.to_address.split(',')]
        content = []
        subj = None
        send_from = self.from_address
        for field in form:
            if 'inquiry' in field.name:
                subj = field.value()
            elif 'email' in field.name.lower():
                send_from = field.value()
            value = field.value()
            if isinstance(value, list):
                value = ', '.join(value)
            content.append('{}: {}'.format(field.label, value))
        content = '\n'.join(content)
        if subj:
            send_mail(subj, content, addresses, send_from,)
        else:
            send_mail(self.subject, content, addresses, send_from,)
示例#3
0
class FormPage(AbstractEmailForm):
    intro = models.TextField(blank=True)
    thank_you_text = models.TextField(blank=True)

    content_panels = AbstractEmailForm.content_panels + [
        FormSubmissionsPanel(),
        FieldPanel('intro', classname="full"),
        InlinePanel('form_fields', label="Form fields"),
        FieldPanel('thank_you_text', classname="full"),
        MultiFieldPanel([
            FieldRowPanel([
                FieldPanel('from_address', classname="col6"),
                FieldPanel('to_address', classname="col6"),
            ]),
            FieldPanel('subject'),
        ], "Email"),
    ]
示例#4
0
class FormPage(WagtailCaptchaEmailForm, MenuPage):
    intro = RichTextField(blank=True)
    thank_you_text = RichTextField(blank=True)

    content_panels = [
        FormSubmissionsPanel(),
        FieldPanel('title', classname="full title"),
        FieldPanel('intro', classname="full"),
        InlinePanel('form_fields', label="Form fields"),
        FieldPanel('thank_you_text', classname="full"),
        MultiFieldPanel([
            FieldRowPanel([
                FieldPanel('from_address', classname="col6"),
                FieldPanel('to_address', classname="col6"),
            ]),
            FieldPanel('subject'),
        ], "Email"),
    ]
示例#5
0
class FormPage(AbstractEmailForm):
    sub_header = models.TextField(default="")
    intro = RichTextField(blank=True)
    thank_you_text = RichTextField(blank=True)

    content_panels = AbstractEmailForm.content_panels + [
        FormSubmissionsPanel(),
        FieldPanel('sub_header'),
        FieldPanel('intro', classname='full'),
        InlinePanel('form_fields', label='Form fields'),
        FieldPanel('thank_you_text', classname='full'),
        MultiFieldPanel([
            FieldRowPanel([
                FieldPanel('from_address', classname='col6'),
                FieldPanel('to_address', classname='col6'),
            ]),
            FieldPanel('subject')
        ], 'Email'),
    ]
示例#6
0
class ContactPage(AbstractForm):
    intro = RichTextField()
    thankyou_text = RichTextField(blank=True)

    search_fields = Page.search_fields + [SearchField('intro')]

    content_panels = AbstractForm.content_panels + [
        FormSubmissionsPanel(),
        FieldPanel('intro', classname="full"),
        InlinePanel('form_fields', label='Form Fields'),
        FieldPanel('thankyou_text', classname="full"),
    ]

    def process_form_submission(self, form):

        results = super(ContactPage, self).process_form_submission(form)
        print('form:', form.cleaned_data)
        print('results:', results)
        return results
示例#7
0
class FormPage(AbstractEmailForm):
    intro = RichTextField(blank=True)
    thank_you_text = RichTextField(blank=True)

    # # Overight mail function to send email in a format friendly to google calendar
    # def send_mail(self, form):
    #     addresses = [x.strip() for x in self.to_address.split(',')]
    #
    #     # Add submission date to subject string
    #     submitted_date_str = date.today().strftime('%x')
    #     subject = self.subject + " - " + submitted_date_str
    #
    #     # Create email content from template using form values as context
    #     template = '/form/email_template.html'
    #     context = {}
    #     for field in form:
    #         context[field.label] = field.value()
    #     email_content = render_to_string(template, context)
    #
    #     send_mail(subject, email_content, addresses, self.from_address)

    content_panels = AbstractEmailForm.content_panels + [
        FormSubmissionsPanel(),
        FieldPanel('intro', classname="full"),
        InlinePanel('form_fields', label="Form fields"),
        FieldPanel('thank_you_text', classname="full"),
        MultiFieldPanel([
            FieldRowPanel([
                FieldPanel('from_address', classname="col6"),
                FieldPanel('to_address', classname="col6"),
            ]),
            FieldPanel('subject'),
        ], "Email"),
    ]

    feed_image = models.ForeignKey('wagtailimages.Image',
                                   null=True,
                                   blank=True,
                                   on_delete=models.SET_NULL,
                                   related_name='+')
示例#8
0
class FormPage(AbstractEmailForm):
    intro = RichTextField(blank=True)
    followup_text = RichTextField(blank=True)
    subtitle = RichTextField(default='Get in touch')
    thank_you_text = RichTextField(blank=True)

    content_panels = AbstractEmailForm.content_panels + [
        FormSubmissionsPanel(),
        FieldPanel('subtitle', classname="full"),
        FieldPanel('intro', classname="full"),
        InlinePanel('form_fields', label="Form fields"),
        FieldPanel('followup_text', classname="full"),
        FieldPanel('thank_you_text', classname="full"),
        MultiFieldPanel([
            FieldRowPanel([
                FieldPanel('from_address', classname="col6"),
                FieldPanel('to_address', classname="col6"),
            ]),
            FieldPanel('subject'),
        ], "Email"),
    ]

    form_builder = CaptchaFormBuilder
示例#9
0
class EmailFormPage(AbstractEmailForm):
    intro = RichTextField(blank=True)
    thank_you_text = RichTextField(blank=True)

    image = models.ForeignKey('wagtailimages.Image',
                              on_delete=models.SET_NULL,
                              related_name='+',
                              null=True,
                              blank=True)

    content_panels = AbstractEmailForm.content_panels + [
        FormSubmissionsPanel(),
        FieldPanel('intro'),
        InlinePanel('form_fields', label="Form fields"),
        FieldPanel('thank_you_text'),
        ImageChooserPanel('image'),
        MultiFieldPanel([
            FieldRowPanel([
                FieldPanel('from_address', classname="col6"),
                FieldPanel('to_address', classname="col6"),
            ]),
            FieldPanel('subject'),
        ], "Email"),
    ]