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 SignUpForm(Form): """Sign up form.""" name = wtf.TextField('Name', validators=[ wtf.Required(), wtf.Length(max=100), ], description='e.g. Johnny') primary_email = wtf.TextField('E-mail', validators=[ wtf.Required(), wtf.Email(), wtf.Length(max=100), ]) password = wtf.PasswordField('Password', validators=[ wtf.Required(), ]) password_check = wtf.PasswordField('Password once more', validators=[ wtf.EqualTo( 'password', message='Passwords must match'), ], description='protection against typos')
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 EventForm(Form): """Form to create or edit an event.""" name = wtf.TextField('Name', validators=[ wtf.Required(), wtf.Length(max=200), ]) starts_at = wtf.DateTimeField('When', format='%Y-%m-%d %H:%M') venue = wtf.TextField('Where', validators=[ wtf.Length(max=200), ]) description = wtf.TextAreaField('What') contacts_invited_ids_str = wtf.HiddenField()
class SignupForm(wtf.Form): email = wtf.TextField('email', validators=[ wtf.Required(message=u'请填写电子邮件'), wtf.Email(message=u'无效的电子邮件') ]) nickname = wtf.TextField('nickname', validators=[ wtf.Required(message=u'请填写昵称'), wtf.Length(min=2, max=20, message=u'昵称应为2到20字符') ]) password = wtf.PasswordField('password', validators=[ wtf.Required(message=u'请填写密码'), wtf.Length(min=5, max=20, message=u'密码应为5到20位字符') ]) repassword = wtf.PasswordField('repassword', validators=[ wtf.Required(message=u'请填写确认密码'), wtf.EqualTo('password', message=u'两次输入的密码不一致') ]) next = wtf.HiddenField('next') def __init__(self, *args, **kargs): wtf.Form.__init__(self, *args, **kargs) self.user = None def validate(self): wtf.Form.validate(self) # 验证邮箱是否注册 if not self.email.errors: user = get_user(email=self.email.data) user and self.email.errors.append(u'该邮箱已被注册') self.user = User(email=self.email.data, nickname=self.nickname.data, openids=[ UserOpenID(provider=session['openid_provider'], openid=session['current_openid']) ]) self.user.set_password(self.password.data) self.user.info = UserInfo() return len(self.errors) == 0
class EmailContactForm(Form): """Basic email contact creation form.""" name = wtf.TextField('Name', validators=[ wtf.Required(), wtf.Length(max=100), ], description='e.g. Susan') email = wtf.TextField('E-mail', validators=[ wtf.Required(), wtf.Email(), wtf.Length(max=100), ])
class SigninForm(wtf.Form): email = wtf.TextField('email', validators=[ wtf.Required(message=u'请填写电子邮件'), wtf.Email(message=u'无效的电子邮件') ]) password = wtf.PasswordField('password', validators=[ wtf.Required(message=u'请填写密码'), wtf.Length(min=5, max=20, message=u'密应应为5到20位字符') ]) next = wtf.HiddenField('next') remember = wtf.BooleanField('remember') openid_identifier = wtf.HiddenField('openid_identifier') openid_provider = wtf.HiddenField('openid_provider') def __init__(self, *args, **kargs): wtf.Form.__init__(self, *args, **kargs) self.user = None def validate(self): # 验证邮箱是否注册 if wtf.Form.validate(self): user = get_user(email=self.email.data) if not user: self.email.errors.append(u'该邮箱尚未在本站注册') elif not user.check_password(self.password.data): self.password.errors.append(u'密码错误') else: self.user = user return len(self.errors) == 0
class BitbucketConfigForm(wtf.Form): branches = wtf.TextField( 'Branches', validators=[wtf.Optional(), wtf.Length(max=1024)], description=( 'A comma-seperated list of branches to forward, or blank for all.' ' Ex: "master, dev"')) use_colors = wtf.BooleanField( 'Use Colors', validators=[wtf.Optional()], default=True, description=( 'If checked, commit messages will include minor mIRC coloring.')) show_branch = wtf.BooleanField( 'Show Branch Names', validators=[wtf.Optional()], default=True, description=('If checked, show the branch for a commit.')) show_raw_author = wtf.BooleanField( 'Show Raw Author', validators=[wtf.Optional()], default=False, description=( 'If checked, shows the raw author for a commit. For example,' ' <code>Tyler Kennedy <[email protected]></code> instead of' ' <code>TkTech</code>.'))
class ChannelDetailsForm(wtf.Form): channel = wtf.TextField( 'Channel', validators=[wtf.Required(), wtf.Length(min=1, max=80)]) host = wtf.TextField( 'Host', validators=[wtf.Required(), wtf.Length(min=1, max=255)], default='chat.freenode.net') port = wtf.IntegerField('Port', validators=[wtf.NumberRange(1024, 66552)], default=6667) ssl = wtf.BooleanField('Use SSL', default=False) public = wtf.BooleanField( 'Public', default=True, description=('Allow others to see that this channel exists.'))
class UserPasswordForm(wtf.Form): password = wtf.PasswordField('Password', validators=[ wtf.Required(), wtf.Length(5), wtf.EqualTo('confirm', 'Passwords do not match.'), ]) confirm = wtf.PasswordField('Confirm Password')
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(Form): """Sign in form.""" email = wtf.TextField('E-mail', validators=[ wtf.Required(), wtf.Length(max=100), ]) password = wtf.PasswordField('Password', validators=[ wtf.Required(), ])
class SettingsForm(Form): """Simple settings form.""" name = wtf.TextField('Name', validators=[ wtf.Required(), wtf.Length(max=100), ], description='e.g. Johnny') email = wtf.TextField('E-mail', validators=[ wtf.Required(), wtf.Email(), wtf.Length(max=100), ]) timezone = wtf.SelectField('My timezone is', choices=tz_choices(), validators=[ wtf.Required(), ])
class ActivityForm(RedirectForm): title = wtf.TextField(u'活动标题', validators=[ \ wtf.Required(message=u'请为活动填写一个标题')]) content = wtf.TextAreaField(u'活动简介', validators=[ \ wtf.Length(min=10, max=5000, message=u'简介至少10个字')]) start_time = wtf.TextField(u'开始时间', validators=[ \ wtf.Required(message=u'需要指定开始时间')]) end_time = wtf.TextField(u'结束时间', validators=[ \ wtf.Required(message=u'需要指定结束时间')]) address = wtf.TextField(u'活动地点') latitude = wtf.HiddenField() longitude = wtf.HiddenField()
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 UserDeleteForm(wtf.Form): password = wtf.PasswordField('Password', validators=[ wtf.Required(), wtf.Length(5), wtf.EqualTo('confirm', 'Passwords do not match.'), ]) confirm = wtf.PasswordField('Confirm Password') def validate_password(form, field): if not User.login(g.user.username, field.data): raise wtf.ValidationError('Password is incorrect.')
class GithubConfigForm(wtf.Form): branches = wtf.TextField( 'Branches', validators=[wtf.Optional(), wtf.Length(max=1024)], description=( 'A comma-seperated list of branches to forward, or blank for all.' ' Ex: "master, dev"')) use_colors = wtf.BooleanField( 'Use Colors', validators=[wtf.Optional()], default=True, description=( 'If checked, commit messages will include minor mIRC coloring.')) show_branch = wtf.BooleanField( 'Show Branch Name', validators=[wtf.Optional()], default=True, description=( 'If checked, commit messages will include the branch name.')) show_tags = wtf.BooleanField( 'Show Tags', validators=[wtf.Optional()], default=True, description=('If checked, changes to tags will be shown.')) prefer_username = wtf.BooleanField( 'Prefer Usernames', validators=[wtf.Optional()], default=True, description=( 'If checked, show github usernames instead of commiter name when' ' possible.')) full_project_name = wtf.BooleanField( 'Full Project Name', validators=[wtf.Optional()], default=False, description= ('If checked, show the full github project name (ex: tktech/notifico)' ' instead of the Notifico project name (ex: notifico)')) title_only = wtf.BooleanField( 'Title Only', validators=[wtf.Optional()], default=False, description=( 'If checked, only the commits title (the commit message up to' ' the first new line) will be emitted.')) distinct_only = wtf.BooleanField( 'Distinct Commits Only', validators=[wtf.Optional()], default=True, description=( 'Commits will only be announced the first time they are seen.'))
class TravisConfigForm(wtf.Form): gh_user = wtf.TextField( 'GitHub username', validators=[wtf.Required(), wtf.Length(max=40)], description=('Case-sensitive GitHub username of repository owner.')) repo_name = wtf.TextField( 'Repo name', validators=[wtf.Required(), wtf.Length(max=100)], description=('Case-sensitive name of repository.')) token = wtf.TextField( 'Travis Token', validators=[wtf.Required(), wtf.Length(max=1024)], description= ('Used to authenticate incoming webhooks.<br>' 'Can be found on your ' '<a href="https://travis-ci.org/profile/">Travis CI profile page</a>.' )) use_colors = wtf.BooleanField( 'Use Colors', validators=[wtf.Optional()], default=True, description=( 'If checked, commit messages will include minor mIRC coloring.'))
class EditPassForm(RedirectForm): old_password = wtf.PasswordField( u'当前密码', validators=[wtf.Required(message=u'请提供当前密码')]) password = wtf.PasswordField(u'新密码', validators=[ \ wtf.Required(message=u'请填写新密码,不能少与5位字符'), \ wtf.EqualTo('confirm', message=u'两次输入的密码不一致'), \ wtf.Length(min=5, max=20, message=u'密码应为5到20位字符') ]) confirm = wtf.PasswordField(u'确认密码', validators=[wtf.Required(message=u'请再次输入新密码')]) def validate_old_password(form, field): if not current_user.user.check_password(field.data): raise wtf.ValidationError(u'提供的原始密码不正确')
class ProfileForm(wtf.Form): 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()]) submit = wtf.SubmitField('Save')
class ContentForm(Form): previous_id = wtf.HiddenField(u"Previous revision") title = wtf.TextField(u"Title", validators=[wtf.Required()]) name = wtf.TextField(u"URL name", validators=[wtf.Optional(), valid_name]) author = wtf.TextField( u"Author (optional)", validators=[wtf.Length(max=40)], description="Name of the author. Will default to your name if blank") description = wtf.TextAreaField(u"Summary", description=u"Summary of this page") content = RichTextField(u"Page content", linkify=False, tinymce_options=tinymce_options, sanitize_tags=richtext_sanitize_tags, sanitize_attributes=richtext_sanitize_attributes) template = wtf.TextField( "Template", validators=[wtf.Required()], default='page.html', description=u"Template with which this page will be rendered.") properties = DictField(u"Properties") def validate_previous_id(self, field): if not field.data: field.data = None else: try: field.data = int(field.data) except ValueError: raise wtf.ValidationError("Unknown previous revision") def validate_name(self, field): # TODO pass def validate_author(self, field): if not field.data: field.data = None
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.')
class GithubConfigForm(wtf.Form): branches = wtf.TextField('Branches', validators=[ wtf.Optional(), wtf.Length(max=1024) ], description=( 'A comma-separated list of branches to forward, or blank for all.' ' Ex: "master, dev"' )) events = EventSelectField('Events', choices=[ ('commit_comment_created', 'Commit comment'), ('status_error', 'Commit status: error'), ('status_failure', 'Commit status: failure'), ('status_pending', 'Commit status: pending'), ('status_success', 'Commit status: success'), ('create_branch', 'Create branch'), ('create_tag', 'Create tag'), ('delete_branch', 'Delete branch'), ('delete_tag', 'Delete tag'), ('issue_comment_created', 'Issue comment'), ('issue_comment_deleted', 'Issue comment: deleted'), ('issue_comment_edited', 'Issue comment: edited'), ('issue_assigned', 'Issue: assigned'), ('issue_closed', 'Issue: closed'), ('issue_edited', 'Issue: edited'), ('issue_labeled', 'Issue: labeled'), ('issue_opened', 'Issue: opened'), ('issue_reopened', 'Issue: reopened'), ('issue_unassigned', 'Issue: unassigned'), ('issue_unlabeled', 'Issue: unlabeled'), ('pr_review_created', 'Pull request review comment'), ('pr_review_deleted', 'Pull request review comment: deleted'), ('pr_review_edited', 'Pull request review comment: edited'), ('pr_assigned', 'Pull request: assigned'), ('pr_closed', 'Pull request: closed'), ('pr_edited', 'Pull request: edited'), ('pr_labeled', 'Pull request: labeled'), ('pr_opened', 'Pull request: opened'), ('pr_reopened', 'Pull request: reopened'), ('pr_synchronize', 'Pull request: synchronize'), ('pr_unassigned', 'Pull request: unassigned'), ('pr_unlabeled', 'Pull request: unlabeled'), ('push', 'Push'), ('release_published', 'Release published'), ('member_added', 'Repo: added collaborator'), ('team_add', 'Repo: added to a team'), ('fork', 'Repo: forked'), ('public', 'Repo: made public'), ('watch_started', 'Repo: starred'), ('gollum_created', 'Wiki: created page'), ('gollum_edited', 'Wiki: edited page'), ]) use_colors = wtf.BooleanField('Use Colors', validators=[ wtf.Optional() ], default=True, description=( 'If checked, commit messages will include minor mIRC coloring.' )) show_branch = wtf.BooleanField('Show Branch Name', validators=[ wtf.Optional() ], default=True, description=( 'If checked, commit messages will include the branch name.' )) show_tags = wtf.BooleanField('Show Tags', validators=[ wtf.Optional() ], default=True, description=( 'If checked, changes to tags will be shown.' )) prefer_username = wtf.BooleanField('Prefer Usernames', validators=[ wtf.Optional() ], default=True, description=( 'If checked, show github usernames instead of commiter name when' ' possible.' )) full_project_name = wtf.BooleanField('Full Project Name', validators=[ wtf.Optional() ], default=False, description=( 'If checked, show the full github project name (ex: tktech/notifico)' ' instead of the Notifico project name (ex: notifico)' )) title_only = wtf.BooleanField('Title Only', validators=[ wtf.Optional() ], default=False, description=( 'If checked, only the commits title (the commit message up to' ' the first new line) will be emitted.' )) distinct_only = wtf.BooleanField('Distinct Commits Only', validators=[ wtf.Optional() ], default=True, description=( 'Commits will only be announced the first time they are seen.' ))
class GitlabConfigForm(wtf.Form): branches = wtf.TextField( 'Branches', validators=[wtf.Optional(), wtf.Length(max=1024)], description=( 'A comma-separated of branches to forward, or blank for all.' ' Ex: "master, dev"')) events = EventSelectField( 'Events', choices=[('commit_comment', 'Commit comment'), ('snippet_comment', 'Snippet comment'), ('pipeline_created', 'Pipeline status: created'), ('pipeline_pending', 'Pipeline status: pending'), ('pipeline_running', 'Pipeline status: running'), ('pipeline_failed', 'Pipeline status: failed'), ('pipeline_success', 'Pipeline status: success'), ('pipeline_canceled', 'Pipeline status: canceled'), ('pipeline_skipped', 'Pipeline status: skipped'), ('build_created', 'Build status: created'), ('build_pending', 'Build status: pending'), ('build_running', 'Build status: running'), ('build_failed', 'Build status: failed'), ('build_success', 'Build status: success'), ('build_canceled', 'Build status: canceled'), ('build_skipped', 'Build status: skipped'), ('create_branch', 'Create branch'), ('create_tag', 'Create tag'), ('delete_branch', 'Delete branch'), ('delete_tag', 'Delete tag'), ('issue_comment', 'Issue comment'), ('issue_close', 'Issue: closed'), ('issue_update', 'Issue: updated'), ('issue_open', 'Issue: opened'), ('issue_reopen', 'Issue: reopened'), ('mr_comment', 'Merge request comment'), ('mr_close', 'Merge request: closed'), ('mr_update', 'Merge request: updated'), ('mr_open', 'Merge request: opened'), ('mr_reopen', 'Merge request: reopened'), ('mr_merge', 'Merge request: merged'), ('push', 'Push'), ('wiki_create', 'Wiki: created page'), ('wiki_edit', 'Wiki: edited page')]) use_colors = wtf.BooleanField( 'Use Colors', validators=[wtf.Optional()], default=True, description=( 'If checked, commit messages will include minor mIRC coloring.')) show_branch = wtf.BooleanField( 'Show Branch Name', validators=[wtf.Optional()], default=True, description=( 'If checked, commit messages will include the branch name.')) show_tags = wtf.BooleanField( 'Show Tags', validators=[wtf.Optional()], default=True, description=('If checked, changes to tags will be shown.')) full_project_name = wtf.BooleanField( 'Full Project Name', validators=[wtf.Optional()], default=False, description= ('If checked, show the full gitlab project name (ex: tktech/notifico)' ' instead of the Notifico project name (ex: notifico)')) title_only = wtf.BooleanField( 'Title Only', validators=[wtf.Optional()], default=False, description=( 'If checked, only the commits title (the commit message up to' ' the first new line) will be emitted.'))