本文整理汇总了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'))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)