class PostForm(Form): title = TextField(u"标题", validators=[required(message=u"标题不能为空")], id="post_title") link = TextField(u"链接", default="http://", validators=[optional(), url(message=u"必须是个有效的链接")], id="post_link") description = TextAreaField(u"描述", id="post_description") tags = TextField(u"标签(用逗号分隔)", id="post_tags") access = RadioField(u"谁可以查看?", default=Post.PUBLIC, coerce=int, choices=((Post.PUBLIC, u"任何人"), (Post.FRIENDS, u"好友"), (Post.PRIVATE, u"只有自己"))) submit = SubmitField(u"提交") def __init__(self, *args, **kwargs): self.post = kwargs.get('obj', None) super(PostForm, self).__init__(*args, **kwargs) def validate_link(self, field): posts = Post.query.public().filter_by(link=field.data) if self.post: posts = posts.filter(db.not_(Post.id == self.post.id)) if posts.count(): raise ValidationError, u"这个链接已经有人提交了"
class PostForm(Form): title = TextField(_("Title of your post"), validators=[required(message=_("Title required"))]) link = TextField( _("Link"), validators=[optional(), url(message=_("This is not a valid URL"))]) description = TextAreaField(_("Description")) tags = TextField(_("Tags")) access = RadioField(_("Who can see this post ?"), default=Post.PUBLIC, coerce=int, choices=((Post.PUBLIC, _("Everyone")), (Post.FRIENDS, _("Friends only")), (Post.PRIVATE, _("Just myself")))) submit = SubmitField(_("Save")) def __init__(self, *args, **kwargs): self.post = kwargs.get('obj', None) super(PostForm, self).__init__(*args, **kwargs) def validate_link(self, field): posts = Post.query.public().filter_by(link=field.data) if self.post: posts = posts.filter(db.not_(Post.id == self.post.id)) if posts.count(): raise ValidationError, gettext("This link has already been posted")
class LinkForm(Form): name = TextField(_("Site name"), validators=[required(message=_("Name required"))]) link = TextField(_("link"), validators=[url(message=_("A valid url is required"))]) email = TextField( _("Email"), validators=[email(message=_("A valid email is required"))]) logo = TextField( _("Logo"), validators=[optional(), url(message=_("A valid url is required"))]) description = TextAreaField(_("Description")) submit = SubmitField(_("Save"))
class OpenIdLoginForm(Form): next = HiddenField() openid = TextField("OpenID", validators=[ required(_("OpenID is required")), url(_("OpenID must be a valid URL")) ]) submit = SubmitField(_("Login"))
class CommentForm(Form): email = TextField(_("Email"), validators=[ required(message=_("Email required")), email(message=_("A valid email address is required")) ]) nickname = TextField(_("Nickname"), validators=[required(message=_("Nickname required"))]) website = TextField( _("Website"), validators=[optional(), url(message=_("A valid url is required"))]) comment = TextAreaField( _("Comment"), validators=[required(message=_("Comment required"))]) submit = SubmitField(_("Add comment")) cancel = SubmitField(_("Cancel"))
class LoadPostForm(Form): douban = TextField(u"来自豆瓣:", validators=[url(message=u"必须是个有效的链接")], id="link_submit") submit = SubmitField(u"加载", id="load_data")