server.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:xqz.es 作者: arahayrabedian 项目源码 文件源码
def submit(db):

    # TODO: break this out along with others in to an excuses package.
    class SubmissionForm(Form):
        attribution_name = StringField(
            'Your Name (for future attribution purposes)',
            [
                validators.InputRequired(),
                validators.Length(
                    min=3,
                    max=50,
                    message="Srsly, give us a decent username "
                            "(%(min)d - %(max)d chars),"
                            " doesn't even have to be real."
                )
            ]
        )
        excuse = TextAreaField(
            'What\'s YOUR excuse !?!?',
            [
                validators.Length(
                    min=5,
                    max=140,
                    message="Please provide %(min)d - %(max)d "
                            "characters"),
            ]
        )
        nocaptcha = NoCaptchaField(
            public_key=settings.RECAPTCHA_SITE_KEY,
            private_key=settings.RECAPTCHA_SECRET_KEY,
            secure=True,
        )

    form = SubmissionForm(request.POST, nocaptcha={'ip_address': '127.0.0.1'})

    submitted = False
    if request.method == 'POST' and form.validate():
        excuse_record = Excuse(form.attribution_name.data,
                               form.excuse.data)
        db.add(excuse_record)
        submitted = True

    return template('submit', form=form, submitted=submitted)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号