class ProfileForm(wtf.Form): nickname = wtf.TextField('nickname', validators=[wtf.Required(message=u'请填写昵称')]) slug = wtf.TextField( 'slug', validators=[ wtf.Regexp(regex=r'^([a-zA-Z][a-zA-Z0-9_-]{4,23})?$', message=u'长度应为5~24位,仅能包含数字、英文字母及下划线(_)和减号(-),并且需要以字母开头') ]) phone = wtf.TextField( 'phone', validators=[wtf.Regexp(regex=r'^(1\d{10})?$', message=u'请输入有效的手机号码')]) phone_status = wtf.RadioField('phone_status', choices=[('0', u'不公开'), ('1', u'公开'), ('2', u'仅向会员公开')], default='0') # photo = db.Column(db.String(255), nullable=True) # 存一张照片,既然有线下的聚会的,总得认得人才行 motoo = wtf.TextAreaField( 'motoo', validators=[wtf.Length(min=0, max=255, message=u'座右铭最多为255个字符')]) introduction = wtf.TextAreaField( 'introduction', validators=[wtf.Length(min=0, max=3000, message=u'个人介绍最多为3000个字')]) def __init__(self, *args, **kargs): wtf.Form.__init__(self, *args, **kargs) self.user = None
class UserRegisterForm(wtf.Form): username = wtf.TextField( 'Username', validators=[ wtf.Required(), wtf.Length(min=2, max=50), wtf.Regexp( '^[a-zA-Z0-9_]*$', message= ('Username must only contain a to z, 0 to 9, and underscores.' )) ], description=( 'Your username is public and used as part of your project name.')) email = wtf.TextField('Email', validators=[wtf.Required(), wtf.validators.Email()]) password = wtf.PasswordField('Password', validators=[ wtf.Required(), wtf.Length(5), wtf.EqualTo('confirm', 'Passwords do not match.'), ]) confirm = wtf.PasswordField('Confirm Password') def validate_username(form, field): from notifico.views.account import _reserved username = field.data.strip().lower() if username in _reserved or User.username_exists(username): raise wtf.ValidationError('Sorry, but that username is taken.')
class JobForm(wtf.Form): '''Form for editing a job''' name = wtf.StringField( validators=[wtf.DataRequired(), wtf.Regexp('^[a-zA-Z0-9_\-]*$')]) tasks = ExpandableFieldList(QuerySelectField( 'Task', query_factory=lambda: taskpy.models.Task.query, validators=[wtf.InputRequired()], get_label=lambda x: x.name), min_entries=1)
class PasswordFindingForm(wtf.Form): login = wtf.TextField('Login name', validators=[ wtf.Required(), wtf.Length(2, 45), wtf.Regexp(User.LOGIN_PATTERN) ]) submit = wtf.SubmitField('Find') def validate_login(form, field): if g.session.query(User).filter_by(login=field.data).count() < 1: raise wtf.ValidationError('There is no {0}.'.format(field.data))
class TaskForm(wtf.Form): '''Form for creating a new job''' name = wtf.StringField( validators=[wtf.DataRequired(), wtf.Regexp('^[a-zA-Z0-9_\-]*$')]) script = AceEditorField(validators=[wtf.DataRequired()], default='''#!/usr/bin/env python def main(): print 'Hello world!' if __name__ == '__main__': main() ''')
class SignUpForm(wtf.Form): login = wtf.TextField('Login name', validators=[ wtf.Required(), wtf.Length(2, 45), wtf.Regexp(User.LOGIN_PATTERN) ]) password = wtf.PasswordField('Password', validators=[ wtf.Required(), wtf.EqualTo( 'confirm', message='Passwords must match.') ]) confirm = wtf.PasswordField('Repeat Password', validators=[wtf.Required()]) name = wtf.TextField('Screen name', validators=[wtf.Required(), wtf.Length(1, 45)]) email = wtf.html5.EmailField('Email', validators=[wtf.Optional(), wtf.Email()]) url = wtf.html5.URLField('Website', validators=[wtf.Optional(), wtf.URL()]) @classmethod def get_instance(cls, *args, **kwargs): if ('RECAPTCHA_PUBLIC_KEY' in current_app.config and 'RECAPTCHA_PRIVATE_KEY' in current_app.config): class SignUpForm_recaptcha(cls): recaptcha = wtf.RecaptchaField() submit = wtf.SubmitField('Sign up') return SignUpForm_recaptcha(*args, **kwargs) class SignUpForm_plain(cls): submit = wtf.SubmitField('Sign up') return SignUpForm_plain(*args, **kwargs) def validate_login(form, field): if g.session.query(User).filter_by(login=field.data).count(): raise wtf.ValidationError('{0} is already taken.'.format( field.data))
class ProjectDetailsForm(wtf.Form): name = wtf.TextField( 'Project Name', validators=[ wtf.Required(), wtf.Length(1, 50), wtf.Regexp( r'^[a-zA-Z0-9_\-\.]*$', message=( 'Project name must only contain a to z, 0 to 9, dashes' ' and underscores.')) ]) public = wtf.BooleanField('Public', validators=[], default=True) website = wtf.TextField('Project URL', validators=[ wtf.Optional(), wtf.Length(max=1024), wtf.validators.URL() ])
class SignInForm(wtf.Form): login = wtf.TextField('Login name', validators=[ wtf.Required(), wtf.Length(2, 45), wtf.Regexp(User.LOGIN_PATTERN) ]) password = wtf.PasswordField('Password', validators=[wtf.Required()]) return_url = wtf.HiddenField(validators=[wtf.Optional()]) submit = wtf.SubmitField('Login') def validate_login(form, field): if g.session.query(User).filter_by(login=field.data).count() < 1: raise wtf.ValidationError('There is no {0}.'.format(field.data)) def validate_password(form, field): try: user = g.session.query(User).filter_by(login=form.login.data)[0] except IndexError: pass else: if user.password != field.data: raise wtf.ValidationError('Incorrect password.')