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


Python QuestionForm.validate方法代码示例

本文整理汇总了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})
开发者ID:petr-muller,项目名称:larprunner,代码行数:52,代码来源:games_views.py

示例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')
开发者ID:zpidreamteam,项目名称:ZPI,代码行数:27,代码来源:admin_panel.py

示例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)
开发者ID:laoshanlung,项目名称:flask-demo,代码行数:14,代码来源:api_questions.py

示例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)
开发者ID:DimaWittmann,项目名称:FSecurity,代码行数:20,代码来源:application.py


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