当前位置: 首页>>代码示例>>Python>>正文


Python AnswerForm.validate_on_submit方法代码示例

本文整理汇总了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)
开发者ID:YNCHacks,项目名称:Qanda,代码行数:11,代码来源:views.py

示例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)
开发者ID:nataliamm,项目名称:web_app,代码行数:12,代码来源:views.py

示例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)
开发者ID:scofield1991,项目名称:flaskproj,代码行数:16,代码来源:views.py

示例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)
开发者ID:doubledare704,项目名称:testapp,代码行数:17,代码来源:views.py

示例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)
开发者ID:defesteban,项目名称:research,代码行数:21,代码来源:views.py

示例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)
开发者ID:votopkov,项目名称:questionnaire,代码行数:22,代码来源:views.py

示例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)
开发者ID:alexander-vielimchanitsia,项目名称:Questions-Answers,代码行数:43,代码来源:views.py

示例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)
开发者ID:banzayats,项目名称:simple-faq,代码行数:23,代码来源:views.py

示例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)
开发者ID:Pballer,项目名称:prayer,代码行数:23,代码来源:views.py

示例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)
开发者ID:ahbuntu,项目名称:ece1779,代码行数:26,代码来源:views.py


注:本文中的forms.AnswerForm.validate_on_submit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。