Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
you need to override this method.
"""
return self.form_fields.all()
Provides a body and body-related functionality.
This is abstract so that subclasses can override the body StreamField.
"""
class Meta:
verbose_name = _('CodeRed Web Page')
abstract = True
template = 'coderedcms/pages/web_page.html'
# Child pages should override based on what blocks they want in the body.
# Default is LAYOUT_STREAMBLOCKS which is the fullest editor experience.
body = StreamField(LAYOUT_STREAMBLOCKS, null=True, blank=True)
# Search fields
search_fields = (
CoderedPage.search_fields +
[index.SearchField('body')]
)
# Panels
body_content_panels = [
StreamFieldPanel('body'),
]
@property
def body_preview(self):
"""
A shortened version of the body without HTML tags.
"""
# add spaces between tags for legibility
body = str(self.body).replace('>', '> ')
# strip tags
def get_template(self, request, *args, **kwargs):
"""
Override parent to serve different templates based on querystring.
"""
if 'amp' in request.GET and hasattr(self, 'amp_template'):
seo_settings = SeoSettings.for_site(request.site)
if seo_settings.amp_pages:
if request.is_ajax():
return self.ajax_template or self.amp_template
return self.amp_template
if self.custom_template:
return self.custom_template
return super(CoderedPage, self).get_template(request, args, kwargs)
paged_children = paginator.page(pagenum)
except (PageNotAnInteger, EmptyPage, InvalidPage) as e: # noqa
paged_children = paginator.page(1)
context['index_paginated'] = paged_children
context['index_children'] = all_children
context['content_walls'] = self.get_content_walls(check_child_setting=False)
return context
###############################################################################
# Abstract pages providing pre-built common website functionality, suitable for subclassing.
# These are abstract so subclasses can override fields if desired.
###############################################################################
class CoderedWebPage(CoderedPage):
"""
Provides a body and body-related functionality.
This is abstract so that subclasses can override the body StreamField.
"""
class Meta:
verbose_name = _('CodeRed Web Page')
abstract = True
template = 'coderedcms/pages/web_page.html'
# Child pages should override based on what blocks they want in the body.
# Default is LAYOUT_STREAMBLOCKS which is the fullest editor experience.
body = StreamField(LAYOUT_STREAMBLOCKS, null=True, blank=True)
# Search fields
search_fields = (