本文整理汇总了Python中forms.FeedbackForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python FeedbackForm.validate方法的具体用法?Python FeedbackForm.validate怎么用?Python FeedbackForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.FeedbackForm
的用法示例。
在下文中一共展示了FeedbackForm.validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_feedback
# 需要导入模块: from forms import FeedbackForm [as 别名]
# 或者: from forms.FeedbackForm import validate [as 别名]
def post_feedback(id):
project = Project.query.get_or_404(id)
form = FeedbackForm()
if form.validate():
issue = Document(form.summary.data, form.description.data)
feedback = Feedback()
feedback.project = project
feedback.id = Feedback.get_id_from_doc(issue, project=project)
existing_feedback = Feedback.query.get(feedback.id)
if existing_feedback:
feedback = existing_feedback
if form.selected_recommendation.data:
feedback.selected_recommendation = \
form.selected_recommendation.data
if form.confirmed_recommendation.data:
feedback.confirmed_recommendation = \
form.confirmed_recommendation.data
db.session.add(feedback)
db.session.commit()
return jsonify(result="success")
return jsonify(result="error", errors=form.errors), 400
示例2: feedback
# 需要导入模块: from forms import FeedbackForm [as 别名]
# 或者: from forms.FeedbackForm import validate [as 别名]
def feedback():
# set form
form = FeedbackForm()
# check request type
if request.method == 'POST':
# if post then validate submission
if form.validate() == False:
# if form doesn't validate and flash error
for message in form.name.errors:
flash(message)
for message in form.email.errors:
flash(message)
for message in form.topic.errors:
flash(message)
for message in form.message.errors:
flash(message)
return render_template('feedback.html',
title='Feedback',
form=form)
else:
# if form does validate submit form and send email
msg = Message(form.topic.data, sender=form.email.data, recipients=[app.config["MAIL_USERNAME"]])
msg.body = """
From: %s <%s>
Subject: %s
Message: %s
""" % (form.name.data, form.email.data, form.topic.data, form.message.data)
mail.send(msg)
# return page and flash success
flash('Thank you for the message. I\'ll get back to you shortly.')
return render_template('feedback.html',
title='Feedback',
form=form)
elif request.method == 'GET':
# if get then return page
return render_template('feedback.html',
title='Feedback',
form=form)