src/pyams_content/shared/form/interfaces.py
changeset 1059 34e6d07ea2e9
parent 919 45ff6cd59fe0
child 1332 f580241925b7
equal deleted inserted replaced
1058:1fe028e17f70 1059:34e6d07ea2e9
       
     1 #
       
     2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 
       
    18 from zope.annotation.interfaces import IAttributeAnnotatable
       
    19 from zope.container.constraints import containers, contains
       
    20 from zope.container.interfaces import IContainer, IContained
       
    21 from zope.interface import Interface, Attribute
       
    22 from zope.schema import TextLine, Choice, Bool
       
    23 
       
    24 from pyams_content import _
       
    25 # import interfaces
       
    26 from pyams_content.shared.common.interfaces import ISharedContent, IWfSharedContentPortalContext, \
       
    27     ISharedToolPortalContext
       
    28 # import packages
       
    29 from pyams_i18n.schema import I18nTextLineField, I18nTextField
       
    30 from pyams_utils.schema import MailAddressField, TextLineListField
       
    31 
       
    32 FORM_CONTENT_TYPE = 'form'
       
    33 FORM_CONTENT_NAME = _('Form')
       
    34 
       
    35 FORM_FIELD_CONTAINER_KEY = 'pyams_content.shared.form_fields'
       
    36 
       
    37 
       
    38 class IFormsManager(ISharedToolPortalContext):
       
    39     """Forms manager interface"""
       
    40 
       
    41 
       
    42 class IFormsManagerFactory(Interface):
       
    43     """Forms manager factory interface"""
       
    44 
       
    45 
       
    46 class IFormField(IContained):
       
    47     """Form field interface"""
       
    48 
       
    49     containers('.IFormFieldContainer')
       
    50 
       
    51     name = TextLine(title=_("Field name"),
       
    52                     description=_("Field internal name; must be unique for a given form"),
       
    53                     required=True)
       
    54 
       
    55     field_type = Choice(title=_("Field type"),
       
    56                         description=_("Selected field type"),
       
    57                         vocabulary='PyAMS form field types',
       
    58                         required=True)
       
    59 
       
    60     label = I18nTextLineField(title=_("Label"),
       
    61                               description=_("User field label"),
       
    62                               required=True)
       
    63 
       
    64     description = I18nTextField(title=_("Description"),
       
    65                                 description=_("Field description can be displayed as hint"),
       
    66                                 required=False)
       
    67 
       
    68     placeholder = TextLine(title=_("Placeholder"),
       
    69                            description=_("Some field types like textline can display a placeholder"),
       
    70                            required=False)
       
    71 
       
    72     values = TextLineListField(title=_("Optional values"),
       
    73                                description=_("List of available values (for 'choice' and 'list' field types)"),
       
    74                                required=False)
       
    75 
       
    76     default = I18nTextLineField(title=_("Default value"),
       
    77                                 description=_("Give default value if field type can use it"),
       
    78                                 required=False)
       
    79 
       
    80     required = Bool(title=_("Required?"),
       
    81                     description=_("Select 'yes' to set field as mandatory"),
       
    82                     required=True,
       
    83                     default=False)
       
    84 
       
    85     visible = Bool(title=_("Visible?"),
       
    86                    description=_("Select 'no' to hide given field..."),
       
    87                    required=True,
       
    88                    default=True)
       
    89 
       
    90 
       
    91 class IFormFieldFactory(Interface):
       
    92     """Form field factory interface"""
       
    93 
       
    94     label = Attribute("Factory label")
       
    95     weight = Attribute("Factory weight")
       
    96 
       
    97     def get_schema_field(self, field):
       
    98         """Get schema field matching given form field"""
       
    99 
       
   100 
       
   101 class IFormFieldContainer(IContainer):
       
   102     """Form fields container interface"""
       
   103 
       
   104     contains(IFormField)
       
   105 
       
   106     def append(self, field):
       
   107         """Append given field to container"""
       
   108 
       
   109     def get_fields(self):
       
   110         """Get schema fields matching current fields"""
       
   111 
       
   112 
       
   113 class IFormFieldContainerTarget(Interface):
       
   114     """Form fields container target marker interface"""
       
   115 
       
   116 
       
   117 class IWfForm(IWfSharedContentPortalContext):
       
   118     """Form interface"""
       
   119 
       
   120     user_title = I18nTextLineField(title=_("Form title"),
       
   121                                    required=True)
       
   122 
       
   123     handler = Choice(title=_("Form handler"),
       
   124                      description=_("Select how form data is transmitted"),
       
   125                      vocabulary='PyAMS form handlers')
       
   126 
       
   127     auth_only = Bool(title=_("Authenticated only?"),
       
   128                      description=_("If 'yes', only authenticated users will be able to see and submit form"),
       
   129                      required=True,
       
   130                      default=False)
       
   131 
       
   132     use_captcha = Bool(title=_("Use captcha?"),
       
   133                        description=_("If 'yes', a captcha will be added automatically to the form"),
       
   134                        required=True,
       
   135                        default=True)
       
   136 
       
   137     submit_label = I18nTextLineField(title=_("Submit label"),
       
   138                                      description=_("Label of form submit button"),
       
   139                                      required=True)
       
   140 
       
   141     def query_handler(self, handler=None):
       
   142         """Get form handler utility"""
       
   143 
       
   144 
       
   145 class IWfFormFactory(Interface):
       
   146     """Form factory interface"""
       
   147 
       
   148 
       
   149 class IForm(ISharedContent):
       
   150     """Workflow managed form interface"""
       
   151 
       
   152 
       
   153 #
       
   154 # Form handler
       
   155 #
       
   156 
       
   157 class IFormHandler(Interface):
       
   158     """Form handler interface"""
       
   159 
       
   160     label = Attribute("Handler label")
       
   161     target_interface = Attribute("Handler target marker interface")
       
   162     handler_info = Attribute("Handler info interface")
       
   163 
       
   164     def handle(self, data):
       
   165         """Handle entered data"""
       
   166 
       
   167 
       
   168 class IFormHandlerInfo(Interface):
       
   169     """Base handler info interface"""
       
   170 
       
   171 
       
   172 class IMailtoHandlerInfo(IFormHandlerInfo):
       
   173     """Mailto form handler info interface"""
       
   174 
       
   175     source_address = MailAddressField(title=_("Source address"),
       
   176                                       description=_("Mail address from which form data is sent"),
       
   177                                       required=True)
       
   178 
       
   179     source_name = TextLine(title=_("Source name"),
       
   180                            description=_("Name of mail data sender"),
       
   181                            required=False)
       
   182 
       
   183     target_address = MailAddressField(title=_("Recipient address"),
       
   184                                       description=_("Mail address to which form data is sent"),
       
   185                                       required=True)
       
   186 
       
   187     target_name = TextLine(title=_("Recipient name"),
       
   188                            description=_("Name of data recipient"),
       
   189                            required=False)
       
   190 
       
   191 
       
   192 class IMailtoHandlerTarget(IAttributeAnnotatable):
       
   193     """Mailto handler target marker interface"""