src/pyams_content/shared/form/interfaces/__init__.py
changeset 170 26aefef3d0aa
parent 81 3e37d4dd8e3b
child 492 04503227569d
equal deleted inserted replaced
169:483b0f16e9a6 170:26aefef3d0aa
    15 
    15 
    16 # import standard library
    16 # import standard library
    17 
    17 
    18 # import interfaces
    18 # import interfaces
    19 from pyams_content.shared.common.interfaces import ISharedTool, IWfSharedContent, ISharedContent
    19 from pyams_content.shared.common.interfaces import ISharedTool, IWfSharedContent, ISharedContent
       
    20 from zope.annotation.interfaces import IAttributeAnnotatable
       
    21 from zope.container.interfaces import IContainer, IContained
    20 
    22 
    21 # import packages
    23 # import packages
       
    24 from pyams_i18n.schema import I18nTextLineField, I18nTextField
       
    25 from pyams_utils.schema import MailAddressField, TextLineListField
       
    26 from zope.container.constraints import containers, contains
       
    27 from zope.interface import Interface, Attribute
       
    28 from zope.schema import TextLine, Choice, Bool
    22 
    29 
    23 from pyams_content import _
    30 from pyams_content import _
    24 
    31 
    25 
    32 
    26 FORM_CONTENT_TYPE = 'form'
    33 FORM_CONTENT_TYPE = 'form'
    27 FORM_CONTENT_NAME = _('Form')
    34 FORM_CONTENT_NAME = _('Form')
    28 
    35 
       
    36 FORM_FIELD_CONTAINER_KEY = 'pyams_content.shared.form_fields'
       
    37 
    29 
    38 
    30 class IFormsManager(ISharedTool):
    39 class IFormsManager(ISharedTool):
    31     """Formq manager interface"""
    40     """Formq manager interface"""
    32 
    41 
    33 
    42 
       
    43 class IFormField(IContained):
       
    44     """Form field interface"""
       
    45 
       
    46     containers('.IFormFieldContainer')
       
    47 
       
    48     name = TextLine(title=_("Field name"),
       
    49                     description=_("Field internal name; must be unique for a given form"),
       
    50                     required=True)
       
    51 
       
    52     field_type = Choice(title=_("Field type"),
       
    53                         description=_("Selected field type"),
       
    54                         vocabulary='PyAMS form field types',
       
    55                         required=True)
       
    56 
       
    57     label = I18nTextLineField(title=_("Label"),
       
    58                               description=_("User field label"),
       
    59                               required=True)
       
    60 
       
    61     description = I18nTextField(title=_("Description"),
       
    62                                 description=_("Field description can be displayed as hint"),
       
    63                                 required=False)
       
    64 
       
    65     placeholder = TextLine(title=_("Placeholder"),
       
    66                            description=_("Some field types like textline can display a placeholder"),
       
    67                            required=False)
       
    68 
       
    69     values = TextLineListField(title=_("Optional values"),
       
    70                                description=_("List of available values (for 'choice' and 'list' field types)"),
       
    71                                required=False)
       
    72 
       
    73     default = I18nTextLineField(title=_("Default value"),
       
    74                                 description=_("Give default value if field type can use it"),
       
    75                                 required=False)
       
    76 
       
    77     required = Bool(title=_("Required?"),
       
    78                     description=_("Select 'yes' to set field as mandatory"),
       
    79                     required=True,
       
    80                     default=False)
       
    81 
       
    82     visible = Bool(title=_("Visible?"),
       
    83                    description=_("Select 'no' to hide given field..."),
       
    84                    required=True,
       
    85                    default=True)
       
    86 
       
    87 
       
    88 class IFormFieldFactory(Interface):
       
    89     """Form field factory interface"""
       
    90 
       
    91     label = Attribute("Factory label")
       
    92     weight = Attribute("Factory weight")
       
    93 
       
    94     def get_schema_field(self, field):
       
    95         """Get schema field matching given form field"""
       
    96 
       
    97 
       
    98 class IFormFieldContainer(IContainer):
       
    99     """Form fields container interface"""
       
   100 
       
   101     contains(IFormField)
       
   102 
       
   103     def append(self, field):
       
   104         """Append given field to container"""
       
   105 
       
   106     def get_fields(self):
       
   107         """Get schema fields matching current fields"""
       
   108 
       
   109 
       
   110 class IFormFieldContainerTarget(Interface):
       
   111     """Form fields container target marker interface"""
       
   112 
       
   113 
    34 class IWfForm(IWfSharedContent):
   114 class IWfForm(IWfSharedContent):
    35     """Form interface"""
   115     """Form interface"""
       
   116 
       
   117     user_title = I18nTextLineField(title=_("Form title"),
       
   118                                    required=True)
       
   119 
       
   120     header = I18nTextField(title=_("Form header"),
       
   121                            required=False)
       
   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"""
    36 
   143 
    37 
   144 
    38 class IForm(ISharedContent):
   145 class IForm(ISharedContent):
    39     """Workflow managed form interface"""
   146     """Workflow managed form interface"""
       
   147 
       
   148 
       
   149 #
       
   150 # Form handler
       
   151 #
       
   152 
       
   153 class IFormHandler(Interface):
       
   154     """Form handler interface"""
       
   155 
       
   156     label = Attribute("Handler label")
       
   157     target_interface = Attribute("Handler target marker interface")
       
   158     handler_info = Attribute("Handler info interface")
       
   159 
       
   160     def handle(self, data):
       
   161         """Handle entered data"""
       
   162 
       
   163 
       
   164 class IFormHandlerInfo(Interface):
       
   165     """Base handler info interface"""
       
   166 
       
   167 
       
   168 class IMailtoHandlerInfo(IFormHandlerInfo):
       
   169     """Mailto form handler info interface"""
       
   170 
       
   171     source_address = MailAddressField(title=_("Source address"),
       
   172                                       description=_("Mail address from which form data is sent"),
       
   173                                       required=True)
       
   174 
       
   175     source_name = TextLine(title=_("Source name"),
       
   176                            description=_("Name of mail data sender"),
       
   177                            required=False)
       
   178 
       
   179     target_address = MailAddressField(title=_("Recipient address"),
       
   180                                       description=_("Mail address to which form data is sent"),
       
   181                                       required=True)
       
   182 
       
   183     target_name = TextLine(title=_("Recipient name"),
       
   184                            description=_("Name of data recipient"),
       
   185                            required=False)
       
   186 
       
   187 
       
   188 class IMailtoHandlerTarget(IAttributeAnnotatable):
       
   189     """Mailto handler target marker interface"""