mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-28 10:34:53 +00:00
Remove validate_usage from the wagtailforms.backends API. Since non-expert users are likely to be inheriting from AbstractEmailForm rather than hooking up backends to their own custom form models, it is of marginal usefulness and not worth the added complexity of the metaclass setup
This commit is contained in:
parent
d6910e3db8
commit
ddcd750b7a
3 changed files with 1 additions and 29 deletions
|
|
@ -1,11 +1,6 @@
|
|||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
class BaseFormProcessor(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def validate_usage(page):
|
||||
return True
|
||||
|
||||
def process(self, page, form):
|
||||
return NotImplemented
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
from django.core.exceptions import ImproperlyConfigured
|
||||
from .base import BaseFormProcessor
|
||||
from wagtail.wagtailadmin import tasks
|
||||
|
||||
|
|
@ -7,15 +6,6 @@ class EmailFormProcessor(BaseFormProcessor):
|
|||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def validate_usage(page):
|
||||
try:
|
||||
page._meta.get_field('subject')
|
||||
page._meta.get_field('to_address')
|
||||
page._meta.get_field('from_address')
|
||||
except:
|
||||
raise ImproperlyConfigured("To use the EmailFormProcessor your Page must define the fields: subject, to_address and from_address.")
|
||||
|
||||
def process(self, page, form):
|
||||
if page.to_address:
|
||||
content = '\n'.join([x[1].label + ': ' + form.data.get(x[0]) for x in form.fields.items()])
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from unidecode import unidecode
|
|||
import json
|
||||
import re
|
||||
|
||||
from wagtail.wagtailcore.models import PageBase, Page, Orderable, UserPagePermissionsProxy, get_page_types
|
||||
from wagtail.wagtailcore.models import Page, Orderable, UserPagePermissionsProxy, get_page_types
|
||||
from wagtail.wagtailadmin.edit_handlers import FieldPanel
|
||||
from wagtail.wagtailforms.backends.email import EmailFormProcessor
|
||||
|
||||
|
|
@ -107,22 +107,9 @@ def get_forms_for_user(user):
|
|||
return editable_pages.filter(content_type__in=get_form_types())
|
||||
|
||||
|
||||
class FormBase(PageBase):
|
||||
"""Metaclass for Forms"""
|
||||
def __init__(cls, name, bases, dct):
|
||||
super(FormBase, cls).__init__(name, bases, dct)
|
||||
|
||||
if not cls.is_abstract:
|
||||
# Check if form_processing_backend is ok
|
||||
if hasattr(cls, 'form_processing_backend'):
|
||||
cls.form_processing_backend.validate_usage(cls)
|
||||
|
||||
|
||||
class AbstractForm(Page):
|
||||
"""A Form Page. Pages implementing a form should inhert from it"""
|
||||
|
||||
__metaclass__ = FormBase
|
||||
|
||||
form_builder = FormBuilder
|
||||
is_abstract = True # Don't display me in "Add"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue