Esempio n. 1
0
    def test_set_fields_updates_modified(self):
        # https://github.com/collective/collective.easyform/issues/8
        # Calling set_fields should update the modification date,
        # also in the catalog.
        from collective.easyform.api import set_fields

        # 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 fields.
        fields = get_schema(self.ff1)
        set_fields(self.ff1, fields)

        # 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)
Esempio n. 2
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 test_selectiveFieldMailing(self):
        """ Test selective inclusion of fields in the mailing """

        mailer = get_actions(self.ff1)['mailer']
        fields = dict(topic='test subject',
                      replyto='*****@*****.**',
                      comments='test comments')
        request = self.LoadRequestForm(**fields)

        # make sure all fields are sent unless otherwise specified
        self.messageText = ''
        mailer.onSuccess(fields, request)
        self.assertTrue('te=\nst subject' in self.messageBody
                        and '*****@*****.**' in self.messageBody
                        and 'test comments' in self.messageBody)

        # setting some show fields shouldn't change that
        mailer.showFields = (
            'topic',
            'comments',
        )
        self.messageText = ''
        mailer.onSuccess(fields, request)
        self.assertTrue('te=\nst subject' in self.messageBody
                        and '*****@*****.**' in self.messageBody
                        and 'test comments' in self.messageBody)

        # until we turn off the showAll flag
        mailer.showAll = False
        self.messageText = ''
        mailer.onSuccess(fields, request)
        self.assertTrue('te=\nst subject' in self.messageBody
                        and '*****@*****.**' not in self.messageBody
                        and 'test comments' in self.messageBody)

        # check includeEmpties
        mailer.includeEmpties = False

        # first see if everything's still included
        mailer.showAll = True
        self.messageText = ''
        mailer.onSuccess(fields, request)
        # look for labels
        self.assertTrue(
            self.messageBody.find('Subject') > 0
            and self.messageBody.find('Your E-Mail Address') > 0
            and self.messageBody.find('Comments') > 0)

        # now, turn off required for a field and leave it empty
        fields = get_schema(self.ff1)
        fields['comments'].required = False
        set_fields(self.ff1, fields)
        fields = {'topic': 'test subject', 'replyto': '*****@*****.**'}
        request = self.LoadRequestForm(**fields)
        self.messageText = ''
        mailer.onSuccess(fields, request)
        self.assertIn('Subject', self.messageBody)
        self.assertIn('Your E-Mail Address', self.messageBody)
        self.assertNotIn('Comments', self.messageBody)
    def test_selectiveFieldMailing(self):
        """ Test selective inclusion of fields in the mailing """

        mailer = get_actions(self.ff1)["mailer"]
        fields = dict(topic="test subject",
                      replyto="*****@*****.**",
                      comments="test comments")
        request = self.LoadRequestForm(**fields)

        # make sure all fields are sent unless otherwise specified
        self.messageText = ""
        mailer.onSuccess(fields, request)
        self.assertTrue("te=\nst subject" in self.messageBody
                        and "*****@*****.**" in self.messageBody
                        and "test comments" in self.messageBody)

        # setting some show fields shouldn't change that
        mailer.showFields = ("topic", "comments")
        self.messageText = ""
        mailer.onSuccess(fields, request)
        self.assertTrue("te=\nst subject" in self.messageBody
                        and "*****@*****.**" in self.messageBody
                        and "test comments" in self.messageBody)

        # until we turn off the showAll flag
        mailer.showAll = False
        self.messageText = ""
        mailer.onSuccess(fields, request)
        self.assertTrue("te=\nst subject" in self.messageBody
                        and "*****@*****.**" not in self.messageBody
                        and "test comments" in self.messageBody)

        # check includeEmpties
        mailer.includeEmpties = False

        # first see if everything's still included
        mailer.showAll = True
        self.messageText = ""
        mailer.onSuccess(fields, request)
        # look for labels
        self.assertTrue(
            self.messageBody.find("Subject") > 0
            and self.messageBody.find("Your E-Mail Address") > 0
            and self.messageBody.find("Comments") > 0)

        # now, turn off required for a field and leave it empty
        fields = get_schema(self.ff1)
        fields["comments"].required = False
        set_fields(self.ff1, fields)
        fields = {"topic": "test subject", "replyto": "*****@*****.**"}
        request = self.LoadRequestForm(**fields)
        self.messageText = ""
        mailer.onSuccess(fields, request)
        self.assertIn("Subject", self.messageBody)
        self.assertIn("Your E-Mail Address", self.messageBody)
        self.assertNotIn("Comments", self.messageBody)
    def test_talvalidator2(self):
        fields = get_fields(self.ff1)
        IFieldExtender(fields['comments']).TValidator = "python: !value"
        set_fields(self.ff1, fields)
        view = self.ff1.restrictedTraverse('view')
        form = view.form_instance
        form.update()

        data, errors = form.extractData()
        self.assertEqual(len(errors), 1)
    def test_basevalidator2(self):
        fields = get_fields(self.ff1)
        IFieldExtender(fields['comments']).validators = ["isInt", "isURL"]
        set_fields(self.ff1, fields)
        view = self.ff1.restrictedTraverse('view')
        form = view.form_instance
        form.update()

        data, errors = form.extractData()
        self.assertEqual(len(errors), 1)
    def test_basevalidator2(self):
        fields = get_fields(self.ff1)
        IFieldExtender(fields['comments']).validators = ["isInt", "isURL"]
        set_fields(self.ff1, fields)
        view = self.ff1.restrictedTraverse('view')
        form = view.form_instance
        form.update()

        data, errors = form.extractData()
        self.assertEqual(len(errors), 1)
    def test_talvalidator2(self):
        fields = get_fields(self.ff1)
        IFieldExtender(fields['comments']).TValidator = "python: !value"
        set_fields(self.ff1, fields)
        view = self.ff1.restrictedTraverse('view')
        form = view.form_instance
        form.update()

        data, errors = form.extractData()
        self.assertEqual(len(errors), 1)
    def test_basevalidator(self):
        fields = get_fields(self.ff1)
        IFieldExtender(fields['replyto']).validators = ["isEmail"]
        set_fields(self.ff1, fields)
        view = self.ff1.restrictedTraverse('view')
        form = view.form_instance
        form.update()

        data, errors = form.extractData()
        self.assertEqual(errors, ())
        self.assertEqual(data, FORM_DATA)
    def test_talvalidator(self):
        fields = get_schema(self.ff1)
        IFieldExtender(fields["comments"]).TValidator = "python: value == 'comments'"
        set_fields(self.ff1, fields)
        view = self.ff1.restrictedTraverse("view")
        form = view.form_instance
        form.update()

        data, errors = form.extractData()
        self.assertEqual(errors, ())
        self.assertEqual(data, FORM_DATA)
    def test_basevalidator(self):
        fields = get_fields(self.ff1)
        IFieldExtender(fields['replyto']).validators = ["isEmail"]
        set_fields(self.ff1, fields)
        view = self.ff1.restrictedTraverse('view')
        form = view.form_instance
        form.update()

        data, errors = form.extractData()
        self.assertEqual(errors, ())
        self.assertEqual(data, FORM_DATA)
Esempio n. 12
0
    def test_talvalidator(self):
        fields = get_schema(self.ff1)
        IFieldExtender(
            fields['comments']).TValidator = "python: value == 'comments'"
        set_fields(self.ff1, fields)
        view = self.ff1.restrictedTraverse('view')
        form = view.form_instance
        form.update()

        data, errors = form.extractData()
        self.assertEqual(errors, ())
        self.assertEqual(data, FORM_DATA)
    def test_basevalidator4(self):

        request = self.layer["request"]
        request.form["form.widgets.replyto"] = None

        fields = get_schema(self.ff1)

        IFieldExtender(fields["replyto"]).validators = ["isEmail"]
        set_fields(self.ff1, fields)
        view = self.ff1.restrictedTraverse("view")
        form = view.form_instance
        form.update()

        data, errors = form.extractData()
        self.assertEqual(len(errors), 1)
Esempio n. 14
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
def updateFields(obj, event):
    set_fields(obj.aq_parent, obj.schema)
    def test_selectiveFieldMailing(self):
        """ Test selective inclusion of fields in the mailing """

        mailer = get_actions(self.ff1)['mailer']
        request = self.LoadRequestForm(
            topic='test subject', replyto='*****@*****.**', comments='test comments')

        # make sure all fields are sent unless otherwise specified
        self.messageText = ''
        mailer.onSuccess(request.form, request)
        self.assertTrue(
            self.messageBody.find('test subject') > 0 and
            self.messageBody.find('*****@*****.**') > 0 and
            self.messageBody.find('test comments') > 0
        )

        # setting some show fields shouldn't change that
        mailer.showFields = ('topic', 'comments',)
        self.messageText = ''
        mailer.onSuccess(request.form, request)
        self.assertTrue(
            self.messageBody.find('test subject') > 0 and
            self.messageBody.find('*****@*****.**') > 0 and
            self.messageBody.find('test comments') > 0
        )

        # until we turn off the showAll flag
        mailer.showAll = False
        self.messageText = ''
        mailer.onSuccess(request.form, request)
        self.assertTrue(
            self.messageBody.find('test subject') > 0 and
            self.messageBody.find('*****@*****.**') < 0 and
            self.messageBody.find('test comments') > 0
        )

        # check includeEmpties
        mailer.includeEmpties = False

        # first see if everything's still included
        mailer.showAll = True
        self.messageText = ''
        mailer.onSuccess(request.form, request)
        # look for labels
        self.assertTrue(
            self.messageBody.find('Subject') > 0 and
            self.messageBody.find('Your E-Mail Address') > 0 and
            self.messageBody.find('Comments') > 0
        )

        # now, turn off required for a field and leave it empty
        fields = get_fields(self.ff1)
        fields['comments'].required = False
        set_fields(self.ff1, fields)
        request = self.LoadRequestForm(
            topic='test subject', replyto='*****@*****.**',)
        self.messageText = ''
        mailer.onSuccess(request.form, request)
        self.assertTrue(
            self.messageBody.find('Subject') > 0 and
            self.messageBody.find('Your E-Mail Address') > 0 and
            self.messageBody.find('Comments') < 0
        )
Esempio n. 17
0
def updateFields(obj, event):
    set_fields(obj.aq_parent, obj.schema)