Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
request,
self.get_template(request),
context
)
return response
def serve(self, request, *args, **kwargs):
form = self.get_form(request, page=self, user=request.user)
if request.method == 'POST':
if self.spam_protection and self.contains_spam(request):
return self.process_spam_request(form, request)
return self.process_form_post(form, request)
return self.process_form_get(form, request)
class CoderedFormPage(CoderedFormMixin, CoderedWebPage):
"""
This is basically a clone of wagtail.contrib.forms.models.AbstractForm
with changes in functionality and extending CoderedWebPage vs wagtailcore.Page.
"""
class Meta:
verbose_name = _('CodeRed Form Page')
abstract = True
template = 'coderedcms/pages/form_page.html'
landing_page_template = 'coderedcms/pages/form_page_landing.html'
base_form_class = WagtailAdminFormPageForm
form_builder = CoderedFormBuilder
body_content_panels = [
class Meta:
verbose_name = _('CodeRed Form Page')
abstract = True
template = 'coderedcms/pages/form_page.html'
landing_page_template = 'coderedcms/pages/form_page_landing.html'
base_form_class = WagtailAdminFormPageForm
form_builder = CoderedFormBuilder
body_content_panels = [
InlinePanel('form_fields', label="Form fields"),
] + \
CoderedWebPage.body_content_panels + \
CoderedFormMixin.body_content_panels + [
FormSubmissionsPanel(),
InlinePanel('confirmation_emails', label=_('Confirmation Emails'))
]
settings_panels = CoderedPage.settings_panels + CoderedFormMixin.settings_panels
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not hasattr(self, 'landing_page_template'):
name, ext = os.path.splitext(self.template)
self.landing_page_template = name + '_landing' + ext
def get_form_fields(self):
"""
Form page expects `form_fields` to be declared.
If you want to change backwards relation name,
return user_submission
# Custom code to ensure that anonymous users get a session key.
if not request.session.session_key:
request.session.create()
user_submission = Submission.objects.filter(
session_key=request.session.session_key, page=self
).order_by('-pk').first()
if user_submission is None:
return Submission(session_key=request.session.session_key,
page=self, form_data='[]')
return user_submission
class CoderedStreamFormPage(CoderedFormMixin, CoderedStreamFormMixin, CoderedWebPage):
class Meta:
verbose_name = _('CodeRed Advanced Form Page')
abstract = True
template = 'coderedcms/pages/stream_form_page.html'
landing_page_template = 'coderedcms/pages/form_page_landing.html'
form_fields = StreamField(STREAMFORM_BLOCKS)
encoder = StreamFormJSONEncoder
body_content_panels = [
StreamFieldPanel('form_fields')
] + \
CoderedFormMixin.body_content_panels + [
InlinePanel('confirmation_emails', label=_('Confirmation Emails'))
]