Beispiel #1
0
class SignupSchema(schemaish.Structure):
    login = schemaish.String(validator=validator.All(
        validator.Required(), validator.Length(min=5, max=32),
        validator.PlainText(), form.AvailableLogin()))
    password = schemaish.String(validator=validator.All(
        validator.Required(), validator.Length(min=5, max=255)))
    email = schemaish.String(
        validator=validator.All(validator.Required(), validator.Length(
            max=255), validator.Email()))
    firstname = schemaish.String(validator=validator.Length(max=255))
    surname = schemaish.String(validator=validator.Length(max=255))
    terms = schemaish.Boolean(validator=form.MustAgree())
Beispiel #2
0
    def form_fields(self):
        min_pw_length = int(get_setting(self.context, 'min_pw_length', 6))
        pwlen = validator.Length(min_pw_length)
        username = karlvalidators.RegularExpression(
            r'^[\w-]+$',
            'Username must contain only letters, numbers, and dashes')
        fields = [
            ('username',
             schemaish.String(
                 validator=validator.All(validator.Required(), username))),
            ('password',
             schemaish.String(
                 validator=validator.All(validator.Required(), pwlen))),
            ('password_confirm',
             schemaish.String(
                 validator=validator.All(validator.Required(), pwlen))),
            ('firstname', schemaish.String(validator=validator.Required())),
            ('lastname', schemaish.String(validator=validator.Required()))
        ]
        member_fields = get_setting(self.context, 'member_fields')
        for field_name in member_fields:
            if field_name in self.fields:
                fields.append((field_name, self.fields[field_name]))

        r = queryMultiAdapter((self.context, self.request),
                              IInvitationBoilerplate)
        if r is None:
            r = DefaultInvitationBoilerplate(self.context)
        if r.terms_and_conditions:
            fields.append(('terms_and_conditions',
                           schemaish.Boolean(validator=validator.Equal(True))))
        if r.privacy_statement:
            fields.append(('accept_privacy_policy',
                           schemaish.Boolean(validator=validator.Equal(True))))
        return fields
Beispiel #3
0
 def form_fields(self):
     title_field = schemaish.String(
         validator=validator.All(
             validator.Length(max=100),
             validator.Required(),
             ))
     fields = [('title', title_field),
               ('tags', tags_field),
               ('description', description_field),
               ]
     return fields
Beispiel #4
0
 def form_fields(self):
     fields = shared_fields()
     title_field = schemaish.String(
         validator=validator.All(validator.Length(
             max=100), validator.Required()))
     fields.insert(0, ('title', title_field))
     security_states = self._get_security_states()
     if security_states:
         fields.insert(4, ('security_state', security_field))
     fields.append(('default_tool', default_tool_field))
     return fields
Beispiel #5
0
 def form_fields(self):
     title_field = schemaish.String(validator=validator.All(
         validator.Length(max=100),
         validator.Required(),
     ))
     fields = [
         ('title', title_field),
         ('tags', tags_field),
         ('text', text_field),
         ('attachments', attachments_field),
     ]
     return fields
Beispiel #6
0
 def form_fields(self):
     fields = []
     title_field = schemaish.String(validator=validator.All(
         validator.Length(max=100),
         validator.Required(),
     ))
     fields.append(('title', title_field))
     fields.append(('tags', tags_field))
     fields.append(('text', text_field))
     fields.append(('attachments', attachments_field))
     security_states = self._get_security_states()
     if security_states:
         fields.append(('security_state', security_field))
     return fields
Beispiel #7
0
 def form_fields(self):
     fields = shared_fields()
     title_field = schemaish.String(validator=validator.All(
         validator.Length(max=100),
         validator.Required(),
         karlvalidators.FolderNameAvailable(self.context),
     ))
     fields.insert(0, ('title', title_field))
     security_states = self._get_security_states()
     if security_states:
         fields.insert(4, ('security_state', security_field))
     fields.append(('default_tool', default_tool_field))
     fields.append(('sendalert_default', sendalert_default_field))
     return fields
Beispiel #8
0
    def form_fields(self):
        required = validator.Required()
        min_pw_length = int(get_setting(self.context, 'min_pw_length', 6))
        pwlen = validator.Length(min_pw_length)
        username = karlvalidators.RegularExpression(
            r'^[\w-]+$',
            'Username must contain only letters, numbers, and dashes')
        fields = [
            ('username',
             schemaish.String(validator=validator.All(required, username))),
            ('password',
             schemaish.String(validator=validator.All(required, pwlen))),
            ('password_confirm',
             schemaish.String(validator=validator.All(required, pwlen))),
            ('firstname', schemaish.String(validator=required)),
            ('lastname', schemaish.String(validator=required)),
            ('phone', schemaish.String()),
            ('extension', schemaish.String()),
            ('organization', schemaish.String()),
            (
                'country',
                schemaish.String(validator=validator.All(
                    validator.OneOf(countries.as_dict.keys()),
                    validator.Required()), ),
            ),
            ('location', schemaish.String()),
            ('department', schemaish.String()),
            ('position', schemaish.String()),
            ('websites',
             schemaish.Sequence(schemaish.String(validator=validator.URL()))),
            ('languages', schemaish.String()),
            ('biography', schemaish.String()),
            ('photo', schemaish.File()),
            ('date_format',
             schemaish.String(
                 validator=validator.OneOf(cultures.as_dict.keys()))),
        ]

        r = queryMultiAdapter((self.context, self.request),
                              IInvitationBoilerplate)
        if r is None:
            r = DefaultInvitationBoilerplate(self.context)
        if r.terms_and_conditions:
            fields.append(('terms_and_conditions',
                           schemaish.Boolean(validator=validator.Equal(True))))
        if r.privacy_statement:
            fields.append(('accept_privacy_policy',
                           schemaish.Boolean(validator=validator.Equal(True))))
        return fields
Beispiel #9
0
 def form_fields(self):
     fields = []
     title_field = schemaish.String(validator=validator.All(
         validator.Length(max=100),
         validator.Required(),
         karlvalidators.FolderNameAvailable(self.context),
     ))
     fields.append(('title', title_field))
     fields.append(('tags', tags_field))
     fields.append(('text', text_field))
     fields.append(('sendalert', sendalert_field))
     security_states = self._get_security_states()
     if security_states:
         fields.append(('security_state', security_field))
     return fields
Beispiel #10
0
 def form_fields(self):
     title_field = schemaish.String(validator=validator.All(
         validator.Length(max=100),
         validator.Required(),
     ))
     fields = [
         ('title', title_field),
         ('tags', tags_field),
         ('text', text_field),
         ('attachments', attachments_field),
         ('photo', photo_field),
         ('caption', caption_field),
         ('publication_date', publication_date_field),
     ]
     return fields
Beispiel #11
0
class ProfileSchema(schemaish.Structure):
    firstname = schemaish.String(
        validator=validator.All(validator.Required(), validator.Length(
            max=64)))
    surname = schemaish.String(
        validator=validator.All(validator.Required(), validator.Length(
            max=64)))
    email = schemaish.String(
        validator=validator.All(validator.Required(), validator.Length(
            max=256), validator.Email()))
    password = schemaish.String(validator=validator.All(
        validator.Length(min=4, max=256), validator.Length(max=256)))

    company = schemaish.String(
        validator=validator.All(validator.Required(), validator.Length(
            max=64)))
    ein = schemaish.String()
    logo = schemaish.String(validator=form.Image())
    address = schemaish.String()
    postal_code = schemaish.String(validator=validator.Length(max=16))
    city = schemaish.String(validator=validator.Length(max=64))
    country = schemaish.String(validator=validator.Length(max=3))
Beispiel #12
0
def OrmToSchema(klass, exclude=["id"]):
    schema = schemaish.Structure()
    typemap = {
        sqlalchemy.types.Boolean: schemaish.Boolean,
        sqlalchemy.types.Numeric: schemaish.Decimal,
        sqlalchemy.types.Integer: schemaish.Integer,
        sqlalchemy.types.String: schemaish.String,
        sqlalchemy.types.Unicode: schemaish.String,
        sqlalchemy.types.UnicodeText: schemaish.String,
    }

    columns = klass.__table__.c
    for id in klass.__table__.c.keys():
        if id in exclude:
            continue
        column = columns.get(id)
        fieldtype = typemap.get(type(column.type), None)
        if fieldtype is None:
            continue

        validators = []
        if not column.nullable:
            validators.append(validator.Required())

        if isinstance(column.type,
                      (sqlalchemy.types.String, sqlalchemy.types.Unicode)):
            if column.type.length:
                validators.append(validator.Length(max=column.type.length))

        if len(validators) > 1:
            field = fieldtype(validator=validator.All(*validators))
        elif len(validators) == 1:
            field = fieldtype(validator=validators[0])
        else:
            field = fieldtype()
        schema.add(id, field)

    return schema
Beispiel #13
0
                related.append(adapted)

    return {'items': related}


security_field = schemaish.String(
    description=('Items marked as private can only be seen by '
                 'members of this community.'))

tags_field = schemaish.Sequence(schemaish.String())

description_field = schemaish.String(
    description=('This description will appear in search results and '
                 'on the community listing page.  Please limit your '
                 'description to 100 words or less'),
    validator=validator.All(validator.Length(max=500), validator.Required()))

text_field = schemaish.String(
    description=('This text will appear on the Overview page for this '
                 'community.  You can use this to describe the '
                 'community or to make a special announcement.'))

tools_field = schemaish.Sequence(
    attr=schemaish.String(),
    description='Select which tools to enable on this community.')

default_tool_field = schemaish.String(
    description=('This is the first page people see when they view this '
                 'community.'))

Beispiel #14
0
            setattr(to_add, field_name, converted[field_name])
        self.after_edit()
        location = resource_url(to_add, request, 'admin.html')
        return HTTPFound(location=location)

    def before_edit(self):
        pass

    def after_edit(self):
        pass


category_schema = [
    ('title',
     schemaish.String(validator=validator.All(
         validator.Length(max=100),
         validator.Required(),
     ))),
]


def edit_categories_view(context, request):
    # There is nothing useful to be done here.
    return HTTPFound(location=resource_url(context, request, 'admin.html'))


class EditCategoryFormController(EditBase):
    page_title = 'Edit Category'
    schema = category_schema

Beispiel #15
0
             old_layout=layout),
        request=request,
        )

tags_field = schemaish.Sequence(schemaish.String())
text_field = schemaish.String()
security_field = schemaish.String(
    description=('Items marked as private can only be seen by '
                 'members of this community.'))
attachments_field = schemaish.Sequence(schemaish.File(),
    title='Attachments',
    )

title_field = schemaish.String(
    validator=validator.All(
        validator.Length(max=100),
        validator.Required(),
        )
    )
description_field = schemaish.String(
    validator=validator.Length(max=500),
    description=("This description will appear in search "
                 "results and on the community listing page. Please "
                 "limit your description to 100 words or less.")
    )

class AddForumFormController(object):
    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.workflow = get_workflow(IForum, 'security', self.context)
Beispiel #16
0
class TestLength(unittest.TestCase):

    type = 'Length'

    fn_min = staticmethod(lambda v: validate.has_length(v, min=3))
    class_fn_min = validator.Length(min=3)

    fn_max = staticmethod(lambda v: validate.has_length(v, max=3))
    class_fn_max = validator.Length(max=3)

    def test_validate_min_pass(self):
        self.section = 'pass'
        values = [
            'abc',
            ['a', 'b', 'c'],
        ]
        check_pass('function', self, self.fn_min, values)
        check_pass('class', self, self.class_fn_min, values)

    def test_validate_min_fail(self):
        self.section = 'fail'
        values = [
            'a',
            'ab',
            '',
            [],
            ['a'],
            ['ab'],
        ]
        check_fail('function', self, self.fn_min, values)
        check_fail('class', self, self.class_fn_min, values)

    def test_validate_max_pass(self):
        self.section = 'pass'
        values = [
            'abc',
            ['a', 'b', 'c'],
            '',
            [],
            ['abcd'],
        ]
        check_pass('function', self, self.fn_max, values)
        check_pass('class', self, self.class_fn_max, values)

    def test_validate_max_fail(self):
        self.section = 'fail'
        values = [
            'abcde',
            'abcd',
            ['a', 'b', 'c', 'd'],
        ]
        check_fail('function', self, self.fn_max, values)
        check_fail('class', self, self.class_fn_max, values)

    def test_messages(self):
        try:
            self.fn_min('')
        except error.Invalid, e:
            assert 'more' in e.message
        try:
            self.fn_max('aaaaaaaaaa')
        except error.Invalid, e:
            assert 'fewer' in e.message
Beispiel #17
0
                related.append(adapted)

    return {'items': related}


security_field = schemaish.String(
    description=('Items marked as private can only be seen by '
                 'members of this community.'))

tags_field = schemaish.Sequence(schemaish.String())

description_field = schemaish.String(
    description=('This description will appear in search results and '
                 'on the community listing page.  Please limit your '
                 'description to 100 words or less'),
    validator=validator.All(validator.Length(max=500),
                                    validator.Required())
    )

text_field =  schemaish.String(
    description=('This text will appear on the Overview page for this '
                 'community.  You can use this to describe the '
                 'community or to make a special announcement.'))

tools_field = schemaish.Sequence(
    attr=schemaish.String(),
    description = 'Select which tools to enable on this community.')

default_tool_field = schemaish.String(
    description=(
        'This is the first page people see when they view this '