Esempio n. 1
0
    def form_fields(self):
        context = self.context
        home_path_field = schemaish.String(
            validator=karlvalidators.PathExists(context),
            description=('The first page to show after logging in. '
                         'Leave blank to show a community or the '
                         'community list.'))
        password_field = schemaish.String(validator=(
            validator.All(karlvalidators.PasswordLength(min_pw_length()),
                          validator.Required())))
        fields = [('login', login_field), ('groups', groups_field),
                  ('home_path', home_path_field), ('password', password_field)]
        fields += super(AddUserFormController, self).form_fields()

        # Get rid of unique email address validation, because we need to do
        # that in the controller so we can manage whether or not email belongs
        # to deactivated user.
        email_field = schemaish.String(
            validator=validator.All(validator.Required(), validator.Email()))
        for i in xrange(len(fields)):
            if fields[i][0] == 'email':
                fields[i] = ('email', email_field)
                break

        return fields
Esempio n. 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
Esempio n. 3
0
 def test_inside_all(self):
     """
     Check when inside an All.
     """
     assert util.validation_includes(validator.All(validator.Required()),
                                     validator.Required)
     assert not util.validation_includes(
         validator.All(validator.Required()), validator.Email)
Esempio n. 4
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())
Esempio n. 5
0
    def test_with_functions(self):
        """
        Check hunting doesn't explode with plain old functions.
        """
        def f(v):
            pass

        assert not util.validation_includes(f, validator.Required)
        assert not util.validation_includes(validator.All(f, f),
                                            validator.Required)
        assert util.validation_includes(validator.All(f, validator.Required()),
                                        validator.Required)
        assert not util.validation_includes(
            validator.Any(f, validator.Required()), validator.Required)
Esempio n. 6
0
File: members.py Progetto: zagy/karl
    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
Esempio n. 7
0
class TestAll_StringRequired(unittest.TestCase):

    type = 'All'
    fn = validator.All(validator.String(), validator.Required())

    def test_validate_pass(self):
        self.section = 'pass'
        values = ['1', '4', u'3']
        check_pass('class', self, self.fn, values)

    def test_validate_fail(self):
        self.section = 'fail'
        values = [
            '',
            u'',
            0,
        ]
        check_fail('class', self, self.fn, values)

    def test_messages(self):
        try:
            self.fn(None)
        except error.Invalid, e:
            self.assertEquals(len(e.errors), 1)
            self.assertEquals('is required', e.errors[0])
        try:
            self.fn(1)
        except error.Invalid, e:
            self.assertEquals(len(e.errors), 1)
            self.assertEquals('must be a string', e.errors[0])
Esempio n. 8
0
    def test_complex_error_all(self):

        schema = schemaish.Structure([
            ("one",
             schemaish.Integer(validator=v.All(
                 v.Required(),
                 v.Integer(),
                 v.Range(min=18),
                 v.Range(min=20),
             ))),
        ])
        f = formish.Form(schema, name="form", add_default_action=False)

        f.add_action('submit', "Submit Me")
        r = webob.Request.blank('http://localhost/',
                                environ={'REQUEST_METHOD': 'POST'})
        r.POST['__formish_form__'] = 'form'
        r.POST['one'] = '9'
        try:
            f.validate(r)
        except fv.FormError:
            assert str(
                f.errors['one']
            ) == 'must be greater than or equal to 18; must be greater than or equal to 20'
            assert str(f['one'].field.errors.exceptions[0]
                       ) == 'must be greater than or equal to 18'
Esempio n. 9
0
class Test_RequiredAndIntegerOrString(unittest.TestCase):

    type = 'RequiredAndIntegerOrString'
    fn = validator.All(validator.Required(),
                       validator.Any(validator.String(), validator.Integer()))

    def test_validate_pass(self):
        self.section = 'pass'
        values = [
            '1',
            1,
            1L,
        ]
        check_pass('class', self, self.fn, values)

    def test_validate_fail(self):
        self.section = 'fail'
        values = [
            0.5,
            datetime.now(),
            None,
        ]
        check_fail('class', self, self.fn, values)

    def test_messages(self):
        try:
            self.fn(datetime.now())
        except error.Invalid, e:
            self.assertEquals(len(e.errors), 2)
            assert 'string' in ''.join(e.errors)
            assert 'integer' in ''.join(e.errors)
Esempio n. 10
0
class InvoiceEntrySchema(schemaish.Structure):
    id = schemaish.Integer()
    description = schemaish.String(validator=validator.Required())
    currency_code = schemaish.String(validator=validator.Required())
    vat = schemaish.Integer(validator=validator.Required())
    unit_price = schemaish.Decimal(validator=validator.Required())
    units = schemaish.Decimal(
        validator=validator.All(validator.Required(), validator.Range(
            min=0.1)))
Esempio n. 11
0
 def form_fields(self):
     email_field = schemaish.String(
         validator=validator.All(validator.Required(), validator.Email(),
                                 karlvalidators.UniqueEmail(self.context)))
     fields = [('firstname', firstname_field), ('lastname', lastname_field),
               ('email', email_field), ('photo', photo_field)]
     for field_name in get_setting(self.context, 'member_fields'):
         if field_name in self.fields:
             fields.append((field_name, self.fields[field_name]))
     return fields
Esempio n. 12
0
 def form_fields(self):
     users = find_users(self.context)
     userid = self.context.__name__
     user = users.get_by_id(userid)
     old_password_field = schemaish.String(
         title="Old Password",
         validator=validator.All(
             validator.Required(),
             karlvalidators.CorrectUserPassword(user),
         ))
     new_password_field = schemaish.String(
         title="New Password",
         validator=validator.All(
             karlvalidators.PasswordLength(min_pw_length()),
             validator.Required()))
     fields = [
         ('old_password', old_password_field),
         ('password', new_password_field),
     ]
     return fields
Esempio n. 13
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
Esempio n. 14
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
Esempio n. 15
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
Esempio n. 16
0
 def form_fields(self):
     min_pw_length = get_setting(None, 'min_pw_length')
     login_field = schemaish.String(validator=validator.Required())
     password_field = schemaish.String(validator=validator.All(
         validator.Required(),
         karlvalidators.PasswordLength(min_pw_length)),
                                       title='New Password')
     fields = [
         ('login', login_field),
         ('password', password_field),
     ]
     return fields
Esempio n. 17
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))
Esempio n. 18
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
Esempio n. 19
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
Esempio n. 20
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
Esempio n. 21
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
Esempio n. 22
0
 def form_fields(self):
     email_field = schemaish.String(
         validator=validator.All(validator.Required(), validator.Email(),
                                 karlvalidators.UniqueEmail(self.context)))
     fields = [('firstname', firstname_field), ('lastname', lastname_field),
               ('email', email_field), ('phone', phone_field),
               ('extension', extension_field), ('fax', fax_field),
               ('department', department_field),
               ('position', position_field),
               ('organization', organization_field),
               ('location', location_field), ('country', country_field),
               ('websites', websites_field), ('languages', languages_field),
               ('biography', biography_field), ('photo', photo_field),
               ('date_format', date_format_field)]
     return fields
Esempio n. 23
0
    def test_complex_form(self):

        one = schemaish.Structure([
            ("a", schemaish.String(validator=v.All(v.Email(), v.Required()))),
            ("b", schemaish.String()),
            ("c", schemaish.Sequence(schemaish.Integer()))
        ])
        two = schemaish.Structure([("a", schemaish.String()), ("b", schemaish.Date()),\
                         ('c', schemaish.Sequence(schemaish.String())), ("d", schemaish.String()), \
                         ("e", schemaish.Integer(validator=v.Required())), ("f", schemaish.String(validator=v.Required())) ])
        schema = schemaish.Structure([("one", one), ("two", two)])
        f = formish.Form(schema, name="form", add_default_action=False)

        f['one.b'].widget = formish.TextArea()
        f['two.a'].widget = formish.SelectChoice(
            [('opt1', "Options 1"), ('opt2', "Option 2")],
            none_option=('-select option-', None))
        f['two.b'].widget = formish.DateParts()
        f['two.c'].widget = formish.CheckboxMultiChoice([('opt1', "Options 1"),
                                                         ('opt2', "Option 2")])
        f['two.d'].widget = formish.RadioChoice([('opt1', "Options 1"),
                                                 ('opt2', "Option 2")])
        f['two.f'].widget = formish.CheckedPassword()

        f.add_action('submit', "Submit Me")
        f.defaults = {
            'one': {
                'a': 'ooteenee',
                'c': ['3', '4', '5']
            },
            'two': {
                'a': 'opt1',
                'b': date(1966, 1, 3),
                'c': ['opt2'],
                'd': 'opt2'
            }
        }
        f()
Esempio n. 24
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
Esempio n. 25
0
def _now():
    if _NOW is not None:
        return _NOW
    return datetime.datetime.now()


PHOTO_DISPLAY_SIZE = (400, 400
                      )  # XXX Wild guess. Any idea what this should be?

tags_field = schemaish.Sequence(schemaish.String())
text_field = schemaish.String()
attachments_field = schemaish.Sequence(schemaish.File(), title='Attachments')
photo_field = schemaish.File()
caption_field = schemaish.String()
publication_date_field = karlattr.KarlDateTime(
    validator=validator.All(validator.Required(), karlvalidator.DateTime()))


class AddNewsItemFormController(object):
    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.filestore = get_filestore(context, request, 'newsitem')
        page_title = getattr(self, 'page_title', 'Add News Item')
        self.api = TemplateAPI(context, request, page_title)
        # calculate locale for this user
        locale = get_user_date_format(context, request)
        default_locale = 'en-US'
        self.datetime_format = consts.python_datetime_formats.get(
            locale, default_locale)
        self.js_date_format = consts.js_date_formats.get(
Esempio n. 26
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.'))

Esempio n. 27
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


class AddCategoryFormController(AddBase):
Esempio n. 28
0
class BaseInvitationFormController(object):
    fields = {
        'firstname':
        schemaish.String(validator=validator.Required()),
        'lastname':
        schemaish.String(validator=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()))
    }

    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.profiles = find_profiles(context)
        self.api = TemplateAPI(context, request)
        self.filestore = get_filestore(context, request, 'accept-invitation')

    @property
    def description(self):
        system_name = get_setting(self.context, 'title', 'KARL')
        return ('You have been invited to join the "%s".  Please begin '
                'by creating a login with profile information.' % system_name)

    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

    def form_widgets(self, fields):
        default_icon = self.api.static_url + '/images/defaultUser.gif'
        system_name = get_setting(self.context, 'title', 'KARL')
        widgets = {
            'biography':
            karlwidgets.RichTextWidget(),
            'password':
            formish.Password(),
            'password_confirm':
            formish.Password(),
            'country':
            formish.SelectChoice(countries),
            'photo':
            karlwidgets.PhotoImageWidget(filestore=self.filestore,
                                         url_base=resource_url(
                                             self.context, self.request,
                                             'photo'),
                                         image_thumbnail_default=default_icon),
            'date_format':
            formish.SelectChoice(cultures),
            'websites':
            formish.TextArea(rows=3, converter_options={'delimiter': '\n'}),
        }

        r = queryMultiAdapter((self.context, self.request),
                              IInvitationBoilerplate)
        if r is None:
            r = DefaultInvitationBoilerplate(self.context)
        terms_text = r.terms_and_conditions
        if terms_text:
            widgets['terms_and_conditions'] = (karlwidgets.AcceptFieldWidget(
                terms_text, 'the %s Terms and Conditions' % system_name))
        privacy_text = r.privacy_statement
        if privacy_text:
            widgets['accept_privacy_policy'] = (karlwidgets.AcceptFieldWidget(
                privacy_text, 'the %s Privacy Policy' % system_name))
        return widgets

    def handle_cancel(self):
        return HTTPFound(location=resource_url(self.context, self.request))

    def get_groups(self):
        return []

    def handle_submit(self, converted):
        context = self.context
        request = self.request
        users = find_users(context)
        profiles = self.profiles

        password = converted['password']
        password_confirm = converted['password_confirm']

        if password != password_confirm:
            msg = 'Mismatched password and confirm'
            raise ValidationError(password_confirm=msg, password=msg)

        username = converted['username']
        if username in profiles:
            raise ValidationError(username='******')

        groups = self.get_groups()
        users.add(username, username, password, groups)
        remember_headers = remember(request, username)

        data = dict(firstname=converted['firstname'],
                    lastname=converted['lastname'],
                    email=context.email)
        for field_name in get_setting(self.context, 'member_fields'):
            if field_name in self.fields:
                data[field_name] = converted[field_name]
        profile = create_content(IProfile, **data)

        profiles[username] = profile
        workflow = get_workflow(IProfile, 'security')
        if workflow is not None:
            workflow.initialize(profile)
        try:
            handle_photo_upload(profile, converted)
        except Invalid, e:
            raise ValidationError(**e.error_dict)

        self.send_mail(username, profile)
        url = self.get_redirect_url()

        # delete it
        del context.__parent__[context.__name__]

        self.filestore.clear()
        return HTTPFound(headers=remember_headers, location=url)
Esempio n. 29
0
from zope.component import getUtility
import datetime
import formish
import random
import schemaish
import urllib

try:
    from hashlib import sha1
except ImportError:
    from sha import new as sha1

max_reset_timedelta = datetime.timedelta(3)  # days

email_field = schemaish.String(validator=validator.All(
    validator.Required(),
    validator.Email(),
))


class ResetRequestFormController(object):
    def __init__(self, context, request):
        self.context = context
        self.request = request

    def form_fields(self):
        return [('email', email_field)]

    def form_widgets(self, fields):
        return {'email': formish.Input(empty='')}

    def __call__(self):
Esempio n. 30
0
class InvoiceSchema(schemaish.Structure):
    payment_term = schemaish.Integer(
        validator=validator.All(validator.Required(), validator.Range(min=1)))
    note = schemaish.String()
    entries = schemaish.Sequence(attr=InvoiceEntrySchema())