diff -r a5e56749ca3d -r 3d259e1718ef src/pyams_content/shared/form/interfaces/__init__.py --- a/src/pyams_content/shared/form/interfaces/__init__.py Fri Oct 12 14:33:03 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,193 +0,0 @@ -# -# Copyright (c) 2008-2015 Thierry Florac -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# - -__docformat__ = 'restructuredtext' - - -# import standard library - -from zope.annotation.interfaces import IAttributeAnnotatable -from zope.container.constraints import containers, contains -from zope.container.interfaces import IContainer, IContained -from zope.interface import Interface, Attribute -from zope.schema import TextLine, Choice, Bool - -from pyams_content import _ -# import interfaces -from pyams_content.shared.common.interfaces import ISharedContent, IWfSharedContentPortalContext, \ - ISharedToolPortalContext -# import packages -from pyams_i18n.schema import I18nTextLineField, I18nTextField -from pyams_utils.schema import MailAddressField, TextLineListField - -FORM_CONTENT_TYPE = 'form' -FORM_CONTENT_NAME = _('Form') - -FORM_FIELD_CONTAINER_KEY = 'pyams_content.shared.form_fields' - - -class IFormsManager(ISharedToolPortalContext): - """Forms manager interface""" - - -class IFormsManagerFactory(Interface): - """Forms manager factory interface""" - - -class IFormField(IContained): - """Form field interface""" - - containers('.IFormFieldContainer') - - name = TextLine(title=_("Field name"), - description=_("Field internal name; must be unique for a given form"), - required=True) - - field_type = Choice(title=_("Field type"), - description=_("Selected field type"), - vocabulary='PyAMS form field types', - required=True) - - label = I18nTextLineField(title=_("Label"), - description=_("User field label"), - required=True) - - description = I18nTextField(title=_("Description"), - description=_("Field description can be displayed as hint"), - required=False) - - placeholder = TextLine(title=_("Placeholder"), - description=_("Some field types like textline can display a placeholder"), - required=False) - - values = TextLineListField(title=_("Optional values"), - description=_("List of available values (for 'choice' and 'list' field types)"), - required=False) - - default = I18nTextLineField(title=_("Default value"), - description=_("Give default value if field type can use it"), - required=False) - - required = Bool(title=_("Required?"), - description=_("Select 'yes' to set field as mandatory"), - required=True, - default=False) - - visible = Bool(title=_("Visible?"), - description=_("Select 'no' to hide given field..."), - required=True, - default=True) - - -class IFormFieldFactory(Interface): - """Form field factory interface""" - - label = Attribute("Factory label") - weight = Attribute("Factory weight") - - def get_schema_field(self, field): - """Get schema field matching given form field""" - - -class IFormFieldContainer(IContainer): - """Form fields container interface""" - - contains(IFormField) - - def append(self, field): - """Append given field to container""" - - def get_fields(self): - """Get schema fields matching current fields""" - - -class IFormFieldContainerTarget(Interface): - """Form fields container target marker interface""" - - -class IWfForm(IWfSharedContentPortalContext): - """Form interface""" - - user_title = I18nTextLineField(title=_("Form title"), - required=True) - - handler = Choice(title=_("Form handler"), - description=_("Select how form data is transmitted"), - vocabulary='PyAMS form handlers') - - auth_only = Bool(title=_("Authenticated only?"), - description=_("If 'yes', only authenticated users will be able to see and submit form"), - required=True, - default=False) - - use_captcha = Bool(title=_("Use captcha?"), - description=_("If 'yes', a captcha will be added automatically to the form"), - required=True, - default=True) - - submit_label = I18nTextLineField(title=_("Submit label"), - description=_("Label of form submit button"), - required=True) - - def query_handler(self, handler=None): - """Get form handler utility""" - - -class IWfFormFactory(Interface): - """Form factory interface""" - - -class IForm(ISharedContent): - """Workflow managed form interface""" - - -# -# Form handler -# - -class IFormHandler(Interface): - """Form handler interface""" - - label = Attribute("Handler label") - target_interface = Attribute("Handler target marker interface") - handler_info = Attribute("Handler info interface") - - def handle(self, data): - """Handle entered data""" - - -class IFormHandlerInfo(Interface): - """Base handler info interface""" - - -class IMailtoHandlerInfo(IFormHandlerInfo): - """Mailto form handler info interface""" - - source_address = MailAddressField(title=_("Source address"), - description=_("Mail address from which form data is sent"), - required=True) - - source_name = TextLine(title=_("Source name"), - description=_("Name of mail data sender"), - required=False) - - target_address = MailAddressField(title=_("Recipient address"), - description=_("Mail address to which form data is sent"), - required=True) - - target_name = TextLine(title=_("Recipient name"), - description=_("Name of data recipient"), - required=False) - - -class IMailtoHandlerTarget(IAttributeAnnotatable): - """Mailto handler target marker interface"""