本文整理汇总了Python中forms.AnswerForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python AnswerForm.validate_on_submit方法的具体用法?Python AnswerForm.validate_on_submit怎么用?Python AnswerForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.AnswerForm
的用法示例。
在下文中一共展示了AnswerForm.validate_on_submit方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: answer
# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import validate_on_submit [as 别名]
def answer(questionid):
form = AnswerForm()
question = Question.objects.get_or_404(id=questionid)
if form.validate_on_submit():
question.answer = form.answer.data
question.save()
flash("Your answer has been saved.")
return redirect(url_for("index"))
return render_template("answer.html", form=form, question=question)
示例2: answers
# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import validate_on_submit [as 别名]
def answers():
form = AnswerForm()
if form.validate_on_submit():
answer = Answer(body=form.answer.data, question_id=form.question_id.data)
db.session.add(answer)
db.session.commit()
flash('Answer was added')
return redirect(url_for('index'))
answers_all = Answer.query.all()
return render_template('answers.html', title='Answers', form=form, answers=answers_all)
示例3: post
# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import validate_on_submit [as 别名]
def post(id):
form = AnswerForm()
post_=Post.query.filter_by(id=id).first()
answers=post_.answers.all()
if request.method == 'POST':
if form.validate_on_submit():
answer = Answer(body = form.answer.data, timestamp = datetime.utcnow(), author = g.user, question=post_)
db.session.add(answer)
db.session.commit()
flash('Your post is now live!')
return redirect(url_for('post', id=post_.id))
#return redirect(url_for('post', post=post, answers=answers, form=form))
return render_template('post.html', post=post_, answers=answers, form=form)
示例4: detail
# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import validate_on_submit [as 别名]
def detail(id):
question = Question.query.get(id)
form = AnswerForm()
if form.validate_on_submit():
user = User.query.filter_by(email=session['email']).first()
answer = Answer(form.answer.data, question, user)
db.session.add(answer)
db.session.commit()
flash('Successfully added answer ')
return redirect(url_for('detail', id=question.id))
if question is None:
flash('Q not found')
return redirect(url_for('index'))
return render_template('question.html', question=question, form=form)
示例5: interpreted
# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import validate_on_submit [as 别名]
def interpreted():
global col_name, theme_name, data
if request.method == 'GET':
col_name, theme_name, data = getData1()
form = AnswerForm()
if form.validate_on_submit():
if form.submit.data:
answer = 1
else:
answer = 0
putData(col_name, theme_name, 1, answer)
message = 'Спасибо за помощь в исследовании :)'
return redirect(url_for('.extra_word', message=message))
message = request.args['message']
return render_template('interpreted.html', title='Research', form=form, data=data, message=message)
示例6: question_detail
# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import validate_on_submit [as 别名]
def question_detail(question_id, page):
question = Question.query.filter_by \
(id=question_id).first()
answers = Answer.query.filter_by \
(question_id=question_id).paginate(page, 5, False)
form = AnswerForm()
if form.validate_on_submit():
answer = Answer(text=form.answer.data, user_id=g.user.id,
timestamp=datetime.datetime.utcnow(),
votes=0,
question_id=question_id)
db.session.add(answer)
db.session.commit()
flash('New answer to question has been posted', 'success')
return redirect(request.referrer)
return render_template('question_detail.html',
title = 'question',
question = question,
answers=answers,
form = form)
示例7: question_review
# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import validate_on_submit [as 别名]
def question_review(id):
# Get the question
question = Question.query.get_or_404(id)
# All answers in this question
answers = Answer.query.filter_by(question_id=id)
author_question = User.query.get(question.user_id)
# author_answer = User.query.get(answers.user_id)
# was form posted?
if request.method == 'POST':
form = AnswerForm(request.form)
if form.validate_on_submit():
answer = Answer(
text=request.form['text'],
date=datetime.now(),
question_id=id,
user_id=current_user.id)
# Answer save in db
db.session.add(answer)
db.session.commit()
return redirect(url_for('question_review', id=id))
else:
# Show errors in form
flash_errors(form)
else:
form = AnswerForm()
return render_template('question_review.html',
form = form,
question = question,
answers = answers,
author_question=author_question,
users = User)
示例8: details
# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import validate_on_submit [as 别名]
def details(id):
question = Question.query.filter_by(id=id).first()
if question == None:
flash(gettext('Question with ID %(id)s not found.', id = id), 'warning')
return redirect(url_for('questions'))
answers = Answer.query.filter_by(question_id=id).all()
vote = request.args.get('vote')
if vote != None:
answer = Answer.query.filter_by(id=vote).first()
answer.votes += 1
db.session.commit()
form = AnswerForm(request.form)
if form.validate_on_submit():
answer = Answer(text=form.text.data,
date=datetime.utcnow(),
owner=question)
db.session.add(answer)
db.session.commit()
flash(gettext('Your answer succesfully posted'), 'success')
return redirect(url_for('questions'))
return render_template("question.html", question=question, form=form, answers=answers)
示例9: answer
# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import validate_on_submit [as 别名]
def answer(id):
post = Post.query.get(id)
if post == None:
flash("Post not found")
return redirect(url_for('index'))
if post.author.id != g.user.id:
flash("You cannot edit this post")
return redirect(url_for('index'))
form = AnswerForm()
if form.validate_on_submit():
post.answered = True
post.answer = form.answer.data
post.answer_time = datetime.utcnow()
db.session.add(post)
db.session.commit()
flash(gettext('Your answer was added!'))
return redirect(url_for('post', id = post.id))
form.answer.data = post.answer
return render_template('answer_post.html',
post = post,
form = form)
示例10: new_answer
# 需要导入模块: from forms import AnswerForm [as 别名]
# 或者: from forms.AnswerForm import validate_on_submit [as 别名]
def new_answer(question_id):
"""Create a new answer corresponding to a question."""
question = Question.get_by_id(question_id)
answerform = AnswerForm()
if request.method == "POST" and answerform.validate_on_submit():
answer = Answer(
content=answerform.content.data,
added_by=users.get_current_user(),
location=get_location(answerform.location.data),
for_question=question,
parent=question.key
)
try:
answer.put()
notify_new_answer(answer)
answer_id = answer.key.id()
flash(u'Answer %s successfully saved.' % answer_id, 'success')
return redirect(url_for('answers_for_question', question_id=question_id))
except CapabilityDisabledError:
flash(u'App Engine Datastore is currently in read-only mode.', 'info')
return redirect(url_for('answers_for_question', question_id=question_id))
return render_template('new_answer.html', question=question, form=answerform)