當前位置: 首頁>>代碼示例>>Python>>正文


Python QuestionForm.validate_on_submit方法代碼示例

本文整理匯總了Python中forms.QuestionForm.validate_on_submit方法的典型用法代碼示例。如果您正苦於以下問題:Python QuestionForm.validate_on_submit方法的具體用法?Python QuestionForm.validate_on_submit怎麽用?Python QuestionForm.validate_on_submit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在forms.QuestionForm的用法示例。


在下文中一共展示了QuestionForm.validate_on_submit方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: new_question

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def new_question():
    """Creates a new question"""
    form = QuestionForm()
    if request.method == 'POST' and form.validate_on_submit():
        question = Question(
            content=form.content.data,
            added_by=users.get_current_user(),
            location=get_location(form.location.data)
        )
        try:
            question.put()
            question_id = question.key.id()

            create_nearby_question(question_id)

            flash(u'Question %s successfully saved.' % question_id, 'success')
            add_question_to_search_index(question)


            return redirect(url_for('list_questions_for_user'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'info')
            return redirect(url_for('list_questions_for_user'))
    else:
        flash_errors(form)
        return redirect(url_for('list_questions_for_user'))
開發者ID:ahbuntu,項目名稱:ece1779,代碼行數:28,代碼來源:views.py

示例2: main

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def main():
	error = None 
	form = QuestionForm()
	if request.method == 'POST':
		if form.validate_on_submit():
			newName = form.name.data
			newEmail = form.email.data
			newQuestion = form.question.data
			new_question = Question(
				newName,
				newEmail,
				newQuestion
			)

			msg = Message("Your question submitted",
					recipients = [newEmail],
					sender = '[email protected]',
					body = u'Hello {}\n Your question was submitted through the site frenchonline. We will answer it ASAP ! '.format(newName)
					)

			admin_msg = Message ("You have a new question",
					recipients = ['[email protected]'],
					sender = '[email protected]',
					body = u'Your contact {} asked a question with the content \n----------\n"{}"\n----------\n, \nPlease answer through this email {}'.format(newName, newQuestion, newEmail)
				)
			db.session.add(new_question)
			db.session.commit()
			mail.send(msg)
			mail.send(admin_msg)
	return render_template('index.html', form = form, error = error)
開發者ID:mohammadgoli,項目名稱:frenchonline,代碼行數:32,代碼來源:views.py

示例3: question_add

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def question_add():
    # was form posted?
    if request.method == 'POST':
        form = QuestionForm(request.form)
        if form.validate_on_submit():
            question = Question(
                title=request.form['title'],
                text=request.form['text'],
                date=datetime.now(),
                user_id=current_user.id)

            # Answer save in db
            db.session.add(question)
            db.session.commit()

            return redirect(url_for('index'))

        else:
            # Show errors in form
            flash_errors(form)

    else:
        form = QuestionForm()

    return render_template('question_add.html', form=form)
開發者ID:alexander-vielimchanitsia,項目名稱:Questions-Answers,代碼行數:27,代碼來源:views.py

示例4: add_question

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def add_question():
    form = QuestionForm()
    if form.validate_on_submit():
        add_question = Questions(question=request.form['question'], user_id=g.user.id)
        db_session.add(add_question)
        db_session.commit()
        flash('Question Add!')
        return redirect(url_for('questions'))
    return render_template('add_question.html', title='Add question', form=form)
開發者ID:zedzew,項目名稱:QueCom,代碼行數:11,代碼來源:views.py

示例5: index

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def index():
    form = QuestionForm()
    if form.validate_on_submit():
        question = Question(body=form.question.data, voite=None)
        db.session.add(question)
        db.session.commit()
        flash('Question was added')
        return redirect(url_for('index'))
    questions_all = Question.query.all()
    return render_template('index.html', title='Home', form=form, questions=questions_all)
開發者ID:nataliamm,項目名稱:web_app,代碼行數:12,代碼來源:views.py

示例6: add

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def add():
    form = QuestionForm(request.form)
    if form.validate_on_submit():
        question = Question(text=form.text.data,
                            date=datetime.utcnow(),
                            owner=current_user)
        db.session.add(question)
        db.session.commit()
        flash(gettext('Your question succesfully posted'), 'success')
        return redirect(url_for('questions'))
    return render_template('add_question.html',
        form = form)
開發者ID:banzayats,項目名稱:simple-faq,代碼行數:14,代碼來源:views.py

示例7: ask

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def ask():
    if 'email' not in session:
        return redirect(url_for('signin'))

    form = QuestionForm()
    if form.validate_on_submit():
        question = Question(form.question.data, User.query.filter_by(email=session['email']).first())
        db.session.add(question)
        db.session.commit()
        flash('Successfully added question !')
        return redirect(url_for('index'))
    return render_template('ask.html', form=form)
開發者ID:doubledare704,項目名稱:testapp,代碼行數:14,代碼來源:views.py

示例8: ask_question

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def ask_question():
    form = QuestionForm()
    if form.validate_on_submit():
        question = Question(text=form.question.data,
                            user_id=g.user.id,
                            timestamp=datetime.datetime.utcnow())
        db.session.add(question)
        db.session.commit()
        flash('New_question has been created')
    return render_template('ask_question.html',
                           title = 'Sign In',
                           form = form)
開發者ID:votopkov,項目名稱:questionnaire,代碼行數:14,代碼來源:views.py

示例9: edit_question

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def edit_question(question_id):
    """Edit a question."""
    question = Question.get_by_id(question_id)
    form = QuestionForm(obj=question)
    user = users.get_current_user()
    if request.method == "POST":
        if form.validate_on_submit():
            question.content=form.data.get('content')
            question.location=form.data.get('location')
            question.put()
            flash(u'Question %s successfully modified.' % question_id, 'success')
            return redirect(url_for('list_questions_for_user'))
    return render_template('edit_question.html', question=question, form=form, user=user)
開發者ID:ahbuntu,項目名稱:ece1779,代碼行數:15,代碼來源:views.py

示例10: new_question

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def new_question():
    form = QuestionForm()
    if form.validate_on_submit():
        title = form.title.data
        body = form.body.data
        tags = form.tags.data
        if tags != "":
            tags = set(map(lambda x: x.strip(), tags.split(",")))
            tag_obj = Tag.objects.first()
            for tag in tags:
                tag_obj.update(add_to_set__tags=tag)
            tag_obj.save()
        else:
            tags = []
        question = Question(username=current_user.username, title=title, body=body, tags=tags)
        question.save()
        return redirect(url_for("index"))
    return render_template("add_question.html", form=form)
開發者ID:Murano,項目名稱:microqa,代碼行數:20,代碼來源:views.py

示例11: addQuestion

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def addQuestion(id_survey, id_section):
    section = Section.query.get(id_section)
    form = QuestionForm()
    # get list of question of this section, to that question depends on the answer to another question
    form.question.query=Question.query.filter(Question.section_id==id_section)
    if form.validate_on_submit():
        question = selectType(form,section)
        db.session.add(question)
        db.session.commit()
        flash('Adding question')
        return redirect(url_for('researcher.addQuestion',id_survey = id_survey, id_section = id_section))
    path=tips_path(section)
    return render_template('/researcher/addEditQuestion.html',
        title = "Question",
        form = form,
        survey = Survey.query.get(id_survey),
        sections = Survey.query.get(id_survey).sections.all(),
        section = section,
        questions = section.questions,
        addQuestion = True,
        question_type = form.questionType.data,
        decision_type = form.decisionType.data,
        operation = form.operation.data,
        path = path)
開發者ID:nukru,項目名稱:projectQ,代碼行數:26,代碼來源:views.py

示例12: editQuestion

# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import validate_on_submit [as 別名]
def editQuestion(id_survey, id_section,id_question):
    question = Question.query.get(id_question)
    form = QuestionForm()
    # get list of question of this section, to that question depends on the answer to another question
    form.question.query=Question.query.filter(Question.section_id==id_section,\
        Question.id!=id_question)
    if form.validate_on_submit():
        q = selectType(form,Section.query.get(id_section))
        for subquestion in question.subquestions:
            subquestion.parent = q
            db.session.add(subquestion)
        q.position=question.position
        db.session.add(q)
        db.session.commit()
        db.session.delete (question)
        db.session.commit()
        db.session.commit()
        flash('Adding question')
        return redirect(url_for('researcher.addQuestion',id_survey = id_survey, id_section = id_section))
    elif request.method != "POST":
        form.text.data = question.text
        form.required.data = question.required
        form.expectedAnswer.data = question.expectedAnswer
        form.maxNumberAttempt.data = question.maxNumberAttempt
        form.help_text.data = question.help_text
        form.is_real_money.data = question.is_real_money
        if isinstance(question, QuestionText):
            form.regularExpression.data = question.regularExpression
            form.isNumber.data = question.isNumber
            form.isNumberFloat.data = question.isNumberFloat
            form.errorMessage.data = question.errorMessage
        if isinstance (question,QuestionChoice):
            if question.is_range:
                form.range_min.data = question.range_min
                form.range_max.data = question.range_max
                form.range_step.data = question.range_step
            else:
                l= question.choices
                if len(l) >0:
                    form.answer1.data = l[0]
                if len(l) >1:
                    form.answer2.data = l[1]
                if len(l) >2:
                    form.answer3.data = l[2]
                if len(l) >3:
                    form.answer4.data = l[3]
                if len(l) >4:
                    form.answer5.data = l[4]
                if len(l) >5:
                    form.answer6.data = l[5]
                if len(l) >6:
                    form.answer7.data = l[6]
                if len(l) >7:
                    form.answer8.data = l[7]
                if len(l) >8:
                    form.answer9.data = l[8]
                if len(l) >9:
                    form.answer10.data = l[9]
                if len(l) >10:
                    form.answer11.data = l[10]
                if len(l) >11:
                    form.answer12.data = l[11]
        if isinstance(question, QuestionLikertScale):
            form.labelMinLikert.data=question.labelMin
            form.labelMaxLikert.data=question.labelMax
        if question.decision=="decision_five":
            form.container.data = question.container[0] if len(question.container)>0 else 0
        
        if question.container is not None:
            if len(question.container)>0 and question.container[0]=="feedback":
                form.feedback.data=True

        # condition of subquestion
        if question.condition is not None:
            form.value.data =question.condition.value

    section =  Section.query.get(id_section)
    path=tips_path(section)
    return render_template('/researcher/addEditQuestion.html',
        title = "Question",
        form = form,
        survey = Survey.query.get(id_survey),
        sections = Survey.query.get(id_survey).sections.all(),
        section = section,
        questions = Section.query.get(id_section).questions,
        editQuestion = True,
        question_type = question.type,
        decision_type = question.decision,
        render = question.render if isinstance(question,QuestionChoice) else "vertical",
        operation = (form.operation.data if question.condition is None else\
            question.condition.operation),
        question = (None if question.parent is None else question.parent_id),
        path = path)
開發者ID:nukru,項目名稱:projectQ,代碼行數:95,代碼來源:views.py


注:本文中的forms.QuestionForm.validate_on_submit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。