本文整理汇总了Python中forms.QuestionForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python QuestionForm.validate方法的具体用法?Python QuestionForm.validate怎么用?Python QuestionForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.QuestionForm
的用法示例。
在下文中一共展示了QuestionForm.validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: game_modify
# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import validate [as 别名]
def game_modify(request, gameid=None, qmod=False):
question_form = None
inst = None
if gameid != "new":
inst = Game.objects.get(id=gameid)
questions = Question.objects.all()
question_form = QuestionForm()
fields = {}
our_questions = inst.questionforgame_set
for question in questions:
fields["%s" % question.id] = BooleanField(label=question.uniq_name, required=False, widget=CheckboxInput)
fields["%s_required" % question.id] = BooleanField(label=" %s povinne" % question.uniq_name, required=False, widget=CheckboxInput)
if question in [ que.question for que in our_questions.all() ]:
fields["%s" % question.id].initial = True
if our_questions.get(question=question).required:
fields["%s_required" % question.id].initial = True
question_form.setFields(fields)
if request.method == 'POST':
if qmod:
form = QuestionForm()
fields={}
for question in Question.objects.all():
fields["%s" % question.id] = BooleanField(label=question.uniq_name, required=False, widget=CheckboxInput)
fields["%s_required" % question.id] = BooleanField(label=" %s povinne" % question.uniq_name, required=False, widget=CheckboxInput)
form.setFields(fields)
form.setData(request.POST)
form.validate(request.POST)
if form.is_valid():
form.save(gameid)
return HttpResponseRedirect('/admin/games/')
else:
form = GameForm(request.POST, instance=inst)
print "We should end here"
if form.is_valid():
form.save()
return HttpResponseRedirect('/admin/games/')
else:
form = GameForm(instance=inst)
return render_to_response('admin/gameform.html',
{'form': form, 'gameid': gameid,
'menuitems' : createMenuItems(),
'user' : request.user,
'title' : "Editace hry",
'questions' : question_form})
示例2: send_newsletter
# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import validate [as 别名]
def send_newsletter():
form = QuestionForm()
if request.method == 'POST':
recievers = Newsletter.query.order_by(Newsletter.id.desc()).all()
if form.validate() == False:
flash('Wymagane wszystkie pola.')
return render_template('admin/send_newsletter.html', form=form)
else:
msg = Message(sender=("[email protected]"))
for reciever in recievers:
msg.add_recipient(reciever.email)
msg.subject = " %s " % (form.subject.data)
msg.body = """
%s
Aby wypisac sie z tego newslettera wejdz w zakladke pomoc na naszej stronie.
""" % (form.message.data)
mail.send(msg)
print 'Newsletter do %s zostal wyslany' % (msg.recipients)
flash('Newsletter zostal wyslany.')
return redirect('/admin/newsletter')
elif request.method == 'GET':
print 'ok'
return render_template('admin/send_newsletter.html',
form=form,
title='Wysylanie newslettera')
示例3: create
# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import validate [as 别名]
def create():
data = request.get_json()
form = QuestionForm(**data)
if form.validate():
form_data = form.data
form_data['ip'] = request.remote_addr
question = g.user.create_question(**form_data)
return jsonify({"data": question.json_data()})
else:
return json_error(type="VALIDATION_FAILED", messages=form.errors)
示例4: question
# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import validate [as 别名]
def question():
form = QuestionForm(request.form)
db = get_db()
(question, answer)= db.cursor().execute("select question, answer from profile where profile_id = ?;", \
[session["id"]]).fetchone()
if request.method == 'POST' and form.validate():
if(answer == form.answer.data):
return redirect(url_for('index'))
flash("Answer is incorrect")
var = {}
var['title'] = 'FSecurity | Question'
var['form'] = form
var['question'] = question
return render_template('question.html', **var)