Example #1
0
def get_form(request):
    schema = Registration()
    for q in get_questions(request):
        schema.add(q, schemaish.String(validator=validatish.Required()))
    form = formish.Form(schema)
    form['password'].widget = formish.CheckedPassword()
    return form
Example #2
0
    def test_nested_form_validation_output(self):
        schema_nested = schemaish.Structure([
            ("one",
             schemaish.Structure([
                 ("a", schemaish.String(validator=validatish.Required())),
                 ("b", schemaish.String()),
                 ("c",
                  schemaish.Structure([("x", schemaish.String()),
                                       ("y", schemaish.String())])),
             ])),
        ])
        # Test passing validation
        name = "Nested Form two"
        form = formish.Form(schema_nested, name)

        request = Request(name, {
            'one.a': 'woot!',
            'one.b': '',
            'one.c.x': '',
            'one.c.y': ''
        })
        expected = {
            'one': {
                'a': u'woot!',
                'b': None,
                'c': {
                    'x': None,
                    'y': None
                }
            }
        }
        self.assert_(form.validate(request) == expected)
        self.assertEquals(form.errors, {})
Example #3
0
 def _schema(self):
     return schemaish.Structure([
         ('seq',
          schemaish.Sequence(
              schemaish.Structure([
                  ('foo', schemaish.String(validator=validatish.Required()))
              ]))),
     ])
Example #4
0
def get_form(request):
    schema = schemaish.Structure()
    schema.add('username', schemaish.String())
    schema.add('password', schemaish.String())
    for q in get_questions(request):
        schema.add(q, schemaish.String(validator=validatish.Required()))
    form = formish.Form(schema)
    form['password'].widget = formish.CheckedPassword()
    return form
Example #5
0
class TestFormData(unittest.TestCase):
    """Build a Simple Form and test that it doesn't raise exceptions on build and that the methods/properties are as expected"""

    schema_nested = schemaish.Structure([
        ("one",
         schemaish.Structure([
             ("a",
              schemaish.String(
                  validator=validatish.Required(),
                  description=
                  "This is a field with name a and title A and has a Required validator"
              )),
             ("b", schemaish.String(title='bee')),
             ("c",
              schemaish.Structure([("x", schemaish.String(title='cee')),
                                   ("y", schemaish.String())])),
         ])),
    ])

    def test_titles(self):

        form = formish.Form(self.schema_nested, 'nested')

        assert form['one.b'].title == 'bee'
        assert form['one.c.x'].title == 'cee'
        form['one.b'].title = 'bee bee cee'
        assert form['one.b'].title == 'bee bee cee'
        form['one.c.x'].title = 'bee bee cee'
        assert form['one.c.x'].title == 'bee bee cee'

    def test_widgets(self):

        form = formish.Form(self.schema_nested, 'nested')

        assert isinstance(form['one.a'].widget.widget, formish.Input)
        form['one.a'].widget = formish.TextArea()
        assert isinstance(form['one.a'].widget.widget, formish.TextArea)

    def test_description(self):

        form = formish.Form(self.schema_nested, 'nested')

        assert str(
            form['one.a'].description
        ) == "This is a field with name a and title A and has a Required validator"
        form['one.a'].description = "This is a new description"
        assert str(form['one.a'].description) == "This is a new description"

    def test_value(self):

        form = formish.Form(self.schema_nested, 'nested')
        self.assertRaises(KeyError, setattr, form['one.a'], 'value', 7)
Example #6
0
class PicassaGalleryStructure(PageStructure):

    gallery_template = schemaish.String()
    gallery = schemaish.String(validator=validatish.Required())

    _widgets = copy.copy(PageStructure._widgets)
    _widgets.update({
        'filters': {
            'widget': formish.TextArea,
            'args': [],
            'kwargs': {
                'cols': 80,
                'rows': 5,
                'empty': ''
            },
        },
    })
Example #7
0
    def test_nested_form_validation_errors(self):
        schema_nested = schemaish.Structure([
            ("one",
             schemaish.Structure([
                 ("a", schemaish.String(validator=validatish.Required())),
                 ("b", schemaish.String()),
                 ("c",
                  schemaish.Structure([("x", schemaish.String()),
                                       ("y", schemaish.String())])),
             ])),
        ])

        name = "Nested Form Two"
        form = formish.Form(schema_nested, name)

        r = {'one.a': '', 'one.b': '', 'one.c.x': '', 'one.c.y': ''}
        request = Request(name, r)

        self.assertRaises(formish.FormError, form.validate, request)

        # Do we get an error
        self.assert_(form.errors['one.a'], 'is_required')
Example #8
0
class BaseStructure(schemaish.Structure):
    def __init__(self, context, *args, **kw):
        self.__context = context
        super(BaseStructure, self).__init__(*args, **kw)
        self.title = ''

    name = schemaish.String(validator=validatish.Required())
    name.readonly = True

    title = schemaish.String()
    description = schemaish.String()
    display_order = schemaish.Integer()

    _widgets = {
        'description': {
            'widget': formish.TextArea,
            'args': [],
            'kwargs': {
                'cols': 80,
                'rows': 5,
                'empty': ''
            },
        },
    }
Example #9
0
class Registration(schemaish.Structure):
    username = schemaish.String(validator=validatish.Required())
    password = schemaish.String(validator=validatish.Required())
Example #10
0
class QueryViewStructure(BaseStructure):

    find_kind = schemaish.String(validator=validatish.Required())
    body = schemaish.String()
    hidden = schemaish.Boolean()
    reparent = schemaish.Boolean()
    filters = schemaish.String()
    order_by = schemaish.String()
    group_by = schemaish.String()
    custom_view = schemaish.String()

    _widgets = copy.copy(BaseStructure._widgets)
    _widgets.update({
        'body': {
            'widget': formish.TextArea,
            'args': [],
            'kwargs': {
                'cols': 80,
                'rows': 25,
                'empty': ''
            },
        },
        'hidden': {
            'widget': formish.Checkbox
        },
        'reparent': {
            'widget': formish.Checkbox
        },
        'filters': {
            'widget': formish.TextArea,
            'args': [],
            'kwargs': {
                'cols': 80,
                'rows': 5,
                'empty': ''
            },
        },
        'order_by': {
            'widget': formish.TextArea,
            'args': [],
            'kwargs': {
                'cols': 80,
                'rows': 5,
                'empty': ''
            },
        },
        'group_by': {
            'widget': formish.TextArea,
            'args': [],
            'kwargs': {
                'cols': 80,
                'rows': 5,
                'empty': ''
            },
        },
        'find_kind': {
            'widget': formish.SelectChoice,
            'kwargs': {
                'options': list_query_types,
            },
        }
    })