コード例 #1
0
    def testReturnError(self):
        ''' Succesful script execution with return error
        '''
        self.createScript()

        actions = get_actions(self.ff1)
        actions['adapter'].ScriptBody = return_error_script
        set_actions(self.ff1, actions)

        self.portal.REQUEST['form.widgets.test_field'] = u'Test field'
        self.portal.REQUEST['form.widgets.topic'] = u'subject'
        self.portal.REQUEST['form.widgets.comments'] = u'some comments'
        self.portal.REQUEST['form.widgets.replyto'] = u'*****@*****.**'
        self.portal.REQUEST['form.buttons.submit'] = u'Submit'

        view = self.ff1.restrictedTraverse('view')
        form = view.form_instance
        form.update()

        errors = form.widgets.errors
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0].message, 'Please enter more text')

        data, errors = form.extractData()
        self.assertEqual(len(errors), 0)

        errors = form.processActions(data)
        self.assertEqual(errors, {'comments': 'Please enter more text'})
コード例 #2
0
    def testReturnError(self):
        ''' Succesful script execution with return error
        '''
        self.createScript()

        actions = get_actions(self.ff1)
        actions['adapter'].ScriptBody = return_error_script
        set_actions(self.ff1, actions)

        self.portal.REQUEST['form.widgets.test_field'] = u'Test field'
        self.portal.REQUEST['form.widgets.topic'] = u'subject'
        self.portal.REQUEST['form.widgets.comments'] = u'some comments'
        self.portal.REQUEST['form.widgets.replyto'] = u'*****@*****.**'
        self.portal.REQUEST['form.buttons.submit'] = u'Submit'

        view = self.ff1.restrictedTraverse('view')
        form = view.form_instance
        form.update()

        errors = form.widgets.errors
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0].message, 'Please enter more text')

        data, errors = form.extractData()
        self.assertEqual(len(errors), 0)

        errors = form.processActions(data)
        self.assertEqual(errors, {'comments': 'Please enter more text'})
コード例 #3
0
    def test_set_actions_updates_modified(self):
        # https://github.com/collective/collective.easyform/issues/8
        # Calling set_actions should update the modification date,
        # also in the catalog.
        from collective.easyform.api import get_actions
        from collective.easyform.api import set_actions

        # Gather the original data.
        catalog = api.portal.get_tool("portal_catalog")
        path = "/".join(self.ff1.getPhysicalPath())
        orig_modified = self.ff1.modified()
        brain = catalog.unrestrictedSearchResults(path=path)[0]
        orig_counter = catalog.getCounter()
        self.assertEqual(brain.modified, orig_modified)

        # Set the actions.
        actions = get_actions(self.ff1)
        set_actions(self.ff1, actions)

        # The modification date on the form should have been updated.
        new_modified = self.ff1.modified()
        self.assertGreater(new_modified, orig_modified)

        # The catalog brain should have the new date
        brain = catalog.unrestrictedSearchResults(path=path)[0]
        self.assertEqual(brain.modified, new_modified)
        self.assertGreater(self.ff1.modified(), orig_modified)

        # The catalog counter should have been increased.
        # This helps invalidate caches because the catalogCounter ETag changes.
        self.assertEqual(catalog.getCounter(), orig_counter + 1)
コード例 #4
0
def create_registration_form(container):
    current_lang = api.portal.get_current_language()
    reg_text = translate(_(u"Registration to"), target_language=current_lang)

    # Create & configure form
    form = api.content.create(
        type="EasyForm",
        title=u"{0} : {1}".format(reg_text, container.Title()),
        container=container,
    )

    form.exclude_from_nav = True

    set_fields(form, IRegistrationForm)
    form.submitLabel = translate(_(u"Register"), target_language=current_lang)
    form.thankstitle = translate(_(u"Thank you"), target_language=current_lang)
    form.thanksdescription = translate(
        _(u"Thank you for your subscription"),
        target_language=current_lang,
    )
    form.includeEmpties = False

    # Configure actions
    IRegistrationActions.setTaggedValue(CONTEXT_KEY, form)
    set_actions(form, IRegistrationActions)

    actions = get_actions(form)
    mailer = actions.get("mailer")
    mailer.msg_subject = reg_text

    form.reindexObject()
    def testReturnError(self):
        """ Succesful script execution with return error
        """
        self.createScript()

        actions = get_actions(self.ff1)
        actions["adapter"].ScriptBody = return_error_script
        set_actions(self.ff1, actions)

        self.portal.REQUEST["form.widgets.test_field"] = u"Test field"
        self.portal.REQUEST["form.widgets.topic"] = u"subject"
        self.portal.REQUEST["form.widgets.comments"] = u"some comments"
        self.portal.REQUEST["form.widgets.replyto"] = u"*****@*****.**"
        self.portal.REQUEST["form.buttons.submit"] = u"Submit"

        view = self.ff1.restrictedTraverse("view")
        form = view.form_instance
        form.update()

        errors = form.widgets.errors
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0].message, "Please enter more text")

        data, errors = form.extractData()
        self.assertEqual(len(errors), 0)

        errors = form.processActions(data)
        self.assertEqual(errors, {"comments": "Please enter more text"})
コード例 #6
0
 def afterSetUp(self):
     super(TestFunctions, self).afterSetUp()
     self.folder.invokeFactory("EasyForm", "ff1")
     self.ff1 = getattr(self.folder, "ff1")
     self.ff1.CSRFProtection = False  # no csrf protection
     self.mailhost = self.folder.MailHost
     self.mailhost._send = self.dummy_send
     actions = get_actions(self.ff1)
     actions["mailer"].recipient_email = u"*****@*****.**"
     set_actions(self.ff1, actions)
 def afterSetUp(self):
     super(TestFunctions, self).afterSetUp()
     self.folder.invokeFactory('EasyForm', 'ff1')
     self.ff1 = getattr(self.folder, 'ff1')
     self.ff1.CSRFProtection = False  # no csrf protection
     self.mailhost = self.folder.MailHost
     self.mailhost._send = self.dummy_send
     actions = get_actions(self.ff1)
     actions['mailer'].recipient_email = u'*****@*****.**'
     set_actions(self.ff1, actions)
コード例 #8
0
 def afterSetUp(self):
     super(TestFunctions, self).afterSetUp()
     self.folder.invokeFactory('EasyForm', 'ff1')
     self.ff1 = getattr(self.folder, 'ff1')
     self.ff1.checkAuthenticator = False  # no csrf protection
     self.mailhost = self.folder.MailHost
     self.mailhost._send = self.dummy_send
     actions = get_actions(self.ff1)
     actions['mailer'].recipient_email = u'*****@*****.**'
     set_actions(self.ff1, actions)
コード例 #9
0
 def afterSetUp(self):
     base.EasyFormTestCase.afterSetUp(self)
     self.folder.invokeFactory('EasyForm', 'ff1')
     self.ff1 = getattr(self.folder, 'ff1')
     self.ff1.title = u'ff1'
     self.ff1.CSRFProtection = False  # no csrf protection
     actions = get_actions(self.ff1)
     actions['mailer'].recipient_email = u'*****@*****.**'
     set_actions(self.ff1, actions)
     self.mailhost = self.folder.MailHost
     self.mailhost._send = self.dummy_send
     classImplements(BaseRequest, IFormLayer)
コード例 #10
0
 def afterSetUp(self):
     base.EasyFormTestCase.afterSetUp(self)
     self.folder.invokeFactory('EasyForm', 'ff1')
     self.ff1 = getattr(self.folder, 'ff1')
     self.ff1.title = u'ff1'
     self.ff1.CSRFProtection = False  # no csrf protection
     actions = get_actions(self.ff1)
     actions['mailer'].recipient_email = u'*****@*****.**'
     set_actions(self.ff1, actions)
     self.mailhost = self.folder.MailHost
     self.mailhost._send = self.dummy_send
     classImplements(BaseRequest, IFormLayer)
コード例 #11
0
def make_form_content(context, content):
    form_prologue = content.get('description').replace('[$NEW_LINE$]',
                                                       '<br />')
    form_obj = createAndPublishContentInContainer(context,
                                                  'EasyForm',
                                                  title=content.get('title'),
                                                  submitLabel=u'Send')
    form_prologue = u'<p>{prologue}</p>'.format(prologue=form_prologue)
    form_obj.formPrologue = t2r(form_prologue)

    fields_model_str = make_form_fields_model(form_obj, content)
    fields_model = loadString(fields_model_str)
    fields_schema = fields_model.schema
    set_fields(form_obj, fields_schema)

    actions_model_str = make_form_actions_model(form_obj, content)
    actions_model = loadString(actions_model_str)
    actions_schema = actions_model.schema
    actions_schema.setTaggedValue(CONTEXT_KEY, form_obj)
    set_actions(form_obj, actions_schema)
    return form_obj
コード例 #12
0
 def setExecCondition(self, value):
     actions = get_actions(self.ff1)
     IActionExtender(actions["mailer"]).execCondition = value
     set_actions(self.ff1, actions)
コード例 #13
0
 def setExecCondition(self, value):
     actions = get_actions(self.ff1)
     IActionExtender(actions['mailer']).execCondition = value
     set_actions(self.ff1, actions)
コード例 #14
0
def updateActions(obj, event):
    set_actions(obj.aq_parent, obj.schema)
def updateActions(obj, event):
    set_actions(obj.aq_parent, obj.schema)