# Path: core/panels.py
# HOME_PAGE_CONTENT_PANELS = [
#     FieldPanel('title', classname="full title"),
#     FieldPanel('body', classname="full")
# ]
# WAGTAIL_PAGE_CONTENT_PANELS = HOME_PAGE_CONTENT_PANELS + [
#     FieldPanel('tags'),
# ]
# WAGTAIL_PAGE_PROMOTE_PANELS = [
#     MultiFieldPanel(Page.promote_panels, "SEO and metadata fields"),
#     ImageChooserPanel('feed_image'),
# ]
# WAGTAIL_SITE_PAGE_PROMOTE_PANELS = [
#     FieldPanel('is_featured'),
# ] + WAGTAIL_PAGE_PROMOTE_PANELS
# WAGTAIL_SITE_PAGE_CONTENT_PANELS = [
#     FieldPanel('title', classname="full title"),
#     FieldPanel('site_url'),
#     ImageChooserPanel('site_screenshot'),
#     FieldPanel('body', classname="full"),
#     FieldPanel('tags'),
#     FieldPanel('in_cooperation_with'),
# ]
# WAGTAIL_COMPANY_PAGE_CONTENT_PANELS = HOME_PAGE_CONTENT_PANELS + [
#     FieldPanel('location'),
#     FieldPanel('company_url'),
#     FieldPanel('github_url'),
#     FieldPanel('twitter_url'),
#     ImageChooserPanel('logo'),
#     FieldPanel('tags'),
#     MultiFieldPanel([
#         FieldPanel('show_map'),
#         MapFieldPanel('coords', classname="gmap gmap--latlng"),
#     ], heading="Coordinates")
# ]
# WAGTAIL_COMPANY_PAGE_SETTINGS_PANELS = Page.settings_panels + [
#     FieldPanel('sites_ordering'),
# ]
# WAGTAIL_COMPANY_INDEX_PAGE_CONTENT_PANELS = Page.content_panels + [
#     FieldPanel('show_map'),
#     FieldPanel('body', classname="full"),
# ]
# SUBMIT_FORM_PAGE_CONTENT_PANELS = [
#     FieldPanel('title', classname="full title"),
#     FieldPanel('body', classname="full"),
#     FieldPanel('thank_you_text', classname="full"),
#     InlinePanel('form_fields', label="Form fields"),
#     MultiFieldPanel([
#         FieldPanel('to_address'),
#         FieldPanel('from_address'),
#         FieldPanel('subject'),
#     ], "Email notification")
# ]
# 
# Path: core/forms.py
# class SubmitFormBuilder(WagtailCaptchaFormBuilder if has_recaptcha() else FormBuilder):
#     def get_form_class(self):
#         form_class = super(SubmitFormBuilder, self).get_form_class()
#         form_class.required_css_class = 'required'
#         return form_class
# 
# Path: core/utilities.py
# def has_recaptcha():
#     """
#     Check if the WagtailCaptcha settings are properly set
#     """
#     wagtailcaptcha_public_key = getattr(settings, 'RECAPTCHA_PUBLIC_KEY', None)
#     wagtailcaptcha_private_key = getattr(settings, 'RECAPTCHA_PRIVATE_KEY', None)
# 
#     return wagtailcaptcha_public_key and wagtailcaptcha_private_key
# 
# def validate_only_one_instance(obj):
#     """
#     Allow only one instance
#     """
#     model = obj.__class__
#     if (model.objects.count() > 0 and obj.id != model.objects.get().id):
#         raise ValidationError("We're sorry but a %s already exists, only one is allowed." % model.__name__)


import os
import re
from bs4 import BeautifulSoup
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models
from django.db.models import Case, Count, Q, Value, When
from django.utils.encoding import python_2_unicode_compatible
from django.utils.html import mark_safe
from modelcluster.fields import ParentalKey
from modelcluster.tags import ClusterTaggableManager
from taggit.models import Tag, TaggedItemBase
from core import panels
from core.forms import SubmitFormBuilder
from core.utilities import has_recaptcha, validate_only_one_instance
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailcore.models import Page
from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField
from wagtail.wagtailsearch import index
from wagtailcaptcha.models import WagtailCaptchaEmailForm
        name, extension = os.path.splitext(image['image'].file.url)
        image['type'] = extension[1:]
        return image

    def __str__(self):
        if self.site_url:
            return '%s - %s' % (self.title, self.site_url)
        return self.title

    class Meta:
        verbose_name = "Site Page"

    content_panels = panels.WAGTAIL_SITE_PAGE_CONTENT_PANELS
    promote_panels = panels.WAGTAIL_SITE_PAGE_PROMOTE_PANELS


class SubmitFormField(AbstractFormField):
    page = ParentalKey('SubmitFormPage', related_name='form_fields')


class SubmitFormPage(WagtailCaptchaEmailForm if has_recaptcha() else AbstractEmailForm):
    """
    Form page, inherits from WagtailCaptchaEmailForm if available, otherwise fallback to AbstractEmailForm
    """

    def __init__(self, *args, **kwargs):
        super(SubmitFormPage, self).__init__(*args, **kwargs)

        # WagtailCaptcha does not respect cls.form_builder and overwrite with its own.
        # See https://github.com/springload/wagtail-django-recaptcha/issues/7 for more info.

# Path: core/panels.py
# HOME_PAGE_CONTENT_PANELS = [
#     FieldPanel('title', classname="full title"),
#     FieldPanel('body', classname="full")
# ]
# WAGTAIL_PAGE_CONTENT_PANELS = HOME_PAGE_CONTENT_PANELS + [
#     FieldPanel('tags'),
# ]
# WAGTAIL_PAGE_PROMOTE_PANELS = [
#     MultiFieldPanel(Page.promote_panels, "SEO and metadata fields"),
#     ImageChooserPanel('feed_image'),
# ]
# WAGTAIL_SITE_PAGE_PROMOTE_PANELS = [
#     FieldPanel('is_featured'),
# ] + WAGTAIL_PAGE_PROMOTE_PANELS
# WAGTAIL_SITE_PAGE_CONTENT_PANELS = [
#     FieldPanel('title', classname="full title"),
#     FieldPanel('site_url'),
#     ImageChooserPanel('site_screenshot'),
#     FieldPanel('body', classname="full"),
#     FieldPanel('tags'),
#     FieldPanel('in_cooperation_with'),
# ]
# WAGTAIL_COMPANY_PAGE_CONTENT_PANELS = HOME_PAGE_CONTENT_PANELS + [
#     FieldPanel('location'),
#     FieldPanel('company_url'),
#     FieldPanel('github_url'),
#     FieldPanel('twitter_url'),
#     ImageChooserPanel('logo'),
#     FieldPanel('tags'),
#     MultiFieldPanel([
#         FieldPanel('show_map'),
#         MapFieldPanel('coords', classname="gmap gmap--latlng"),
#     ], heading="Coordinates")
# ]
# WAGTAIL_COMPANY_PAGE_SETTINGS_PANELS = Page.settings_panels + [
#     FieldPanel('sites_ordering'),
# ]
# WAGTAIL_COMPANY_INDEX_PAGE_CONTENT_PANELS = Page.content_panels + [
#     FieldPanel('show_map'),
#     FieldPanel('body', classname="full"),
# ]
# SUBMIT_FORM_PAGE_CONTENT_PANELS = [
#     FieldPanel('title', classname="full title"),
#     FieldPanel('body', classname="full"),
#     FieldPanel('thank_you_text', classname="full"),
#     InlinePanel('form_fields', label="Form fields"),
#     MultiFieldPanel([
#         FieldPanel('to_address'),
#         FieldPanel('from_address'),
#         FieldPanel('subject'),
#     ], "Email notification")
# ]
# 
# Path: core/forms.py
# class SubmitFormBuilder(WagtailCaptchaFormBuilder if has_recaptcha() else FormBuilder):
#     def get_form_class(self):
#         form_class = super(SubmitFormBuilder, self).get_form_class()
#         form_class.required_css_class = 'required'
#         return form_class
# 
# Path: core/utilities.py
# def has_recaptcha():
#     """
#     Check if the WagtailCaptcha settings are properly set
#     """
#     wagtailcaptcha_public_key = getattr(settings, 'RECAPTCHA_PUBLIC_KEY', None)
#     wagtailcaptcha_private_key = getattr(settings, 'RECAPTCHA_PRIVATE_KEY', None)
# 
#     return wagtailcaptcha_public_key and wagtailcaptcha_private_key
# 
# def validate_only_one_instance(obj):
#     """
#     Allow only one instance
#     """
#     model = obj.__class__
#     if (model.objects.count() > 0 and obj.id != model.objects.get().id):
#         raise ValidationError("We're sorry but a %s already exists, only one is allowed." % model.__name__)


# Path: core/models.py
import os
import re
from bs4 import BeautifulSoup
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models
from django.db.models import Case, Count, Q, Value, When
from django.utils.encoding import python_2_unicode_compatible
from django.utils.html import mark_safe
from modelcluster.fields import ParentalKey
from modelcluster.tags import ClusterTaggableManager
from taggit.models import Tag, TaggedItemBase
from core import panels
from core.forms import SubmitFormBuilder
from core.utilities import has_recaptcha, validate_only_one_instance
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailcore.models import Page
from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField
from wagtail.wagtailsearch import index
from wagtailcaptcha.models import WagtailCaptchaEmailForm

        name, extension = os.path.splitext(image['image'].file.url)
        image['type'] = extension[1:]
        return image

    def __str__(self):
        if self.site_url:
            return '%s - %s' % (self.title, self.site_url)
        return self.title

    class Meta:
        verbose_name = "Site Page"

    content_panels = panels.WAGTAIL_SITE_PAGE_CONTENT_PANELS
    promote_panels = panels.WAGTAIL_SITE_PAGE_PROMOTE_PANELS


class SubmitFormField(AbstractFormField):
    page = ParentalKey('SubmitFormPage', related_name='form_fields')


class SubmitFormPage(WagtailCaptchaEmailForm if has_recaptcha() else AbstractEmailForm):
    """
    Form page, inherits from WagtailCaptchaEmailForm if available, otherwise fallback to AbstractEmailForm
    """

    def __init__(self, *args, **kwargs):
        super(SubmitFormPage, self).__init__(*args, **kwargs)

        # WagtailCaptcha does not respect cls.form_builder and overwrite with its own.
        # See https://github.com/springload/wagtail-django-recaptcha/issues/7 for more info.

        self.form_builder = SubmitFormBuilder