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 PDFForm(Form): #name = TextField(name, validators=[Required()]) pdf = FileField("source pdf file") # URLField landscape = BooleanField("landscape") maxcol = IntegerField("max number of columns", default=2) bpc = IntegerField("bit per color", default=4) dithering = BooleanField("dithering", default=True) # m = DecimalField("default margin", default=0.25) mb = DecimalField("bottom margin", default=0) ml = DecimalField("left margin", default=0) mr = DecimalField("right margin", default=0) mt = DecimalField("top margin", default=0) # color = BooleanField("color", default=False) height = IntegerField("height", default=735) width = IntegerField("width", default=560) astraighten = BooleanField("automatically straighten", default=False) text_justification = RadioField(u'Output Text Justification', default="1", choices=[("0", 'Left'), ("1", 'Center'), ("2", 'Right')]) idpi = IntegerField("pixels per inch for input file", default=300) odpi = IntegerField("pixels per inch for output file", default=167)
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 ProfileForm(Form): photo_img = FileField(u'头像', validators=[]) email = TextField(u'邮箱地址*', validators=[Required(), Email()]) nickname = TextField(u'昵称*', validators=[Required(), Regexp('[\w\d-]{2,20}')]) title = TextField(u'签名*', validators=[Required(), Regexp('.{0,128}')]) sex = RadioField(u'性别*', coerce=int, choices=[(0, u'男人'), (1, u'女人')])
class LoginForm(Form): email = TextField('Email', validators=[Required(), Email()]) password = PasswordField('Password', validators=[Required()]) idle_ttl = RadioField('Idle Session Timeout', default='tmp', choices=[ ('tmp', '20 minutes'), ('day', '8 hours (a normal business day)'), ('week', '8 days (Monday to Monday)'), ]) submit = SubmitField('Login')
class UploadForm(Form): save = FileField('Your save file', [ file.FileRequired(), file.FileAllowed( savefiles, 'Only .user files or .zip or .gz compressed uploads allowed') ]) upload_all = RadioField('Upload all?', choices=[ (1, 'Upload all solutions'), (0, 'Let me choose which solutions to upload') ], default=1, coerce=int) submit = SubmitField('Upload')