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


Python QuestionForm.is_valid方法代码示例

本文整理汇总了Python中forms.QuestionForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python QuestionForm.is_valid方法的具体用法?Python QuestionForm.is_valid怎么用?Python QuestionForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.QuestionForm的用法示例。


在下文中一共展示了QuestionForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: editQuestion

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def editQuestion(request, questionId):
    args={}
    args.update(csrf(request))
    objQuestionForm = QuestionForm(request.POST or None)
    objOptionForm = OptionFrom(request.POST or None)
    if request.method == 'POST':
        flag=False
        
        if request.POST['type_text'] == 'MCQ':
 #           objOptionForm.clean_optionheadertext(sOptionHeaderText=request.POST['option_header_text'],nOptionHeaderID=request.POST['option_header_id'])
            if objQuestionForm.is_valid() and objOptionForm.is_valid():
                flag=True
        else:
            objOptionForm = OptionFrom()
            if objQuestionForm.is_valid():
                flag=True   
                
        if flag == True:
            iOptionHeaderID = None 
            i_UserId = UserDetails.objects.get(user_id=request.session['UserID'])
            if request.POST['type_text'] == 'MCQ':
                if request.POST['option_header_id']=='0':
                    objOptionHeader = OptionHeader.objects.create(title=request.POST['option_header_text'], modified_by=i_UserId, modified_on=timezone.now())
                    iOptionHeaderID = OptionHeader.objects.latest('option_header_id')
                    objOptionForm.save(commit=False, userId=i_UserId, optionHeaderId=iOptionHeaderID)
                    
                else:
                    iOptionHeaderID = OptionHeader.objects.get(option_header_id=request.POST['option_header_id'])
            Question.objects.filter(question_id=request.POST['questionID']).update(question=request.POST['question'],level=request.POST['level'],weight=request.POST['weight'],info=request.POST['info'],intent=request.POST['intent'],type=request.POST['type_text'],option_header=iOptionHeaderID)
            return HttpResponseRedirect("/question/QuestionList")
        else:
            args['optionCreateform']=objOptionForm
            args['questionCreateform']=objQuestionForm         
    else:    
        objQuestion=Question.objects.get(question_id=int(questionId))
        
        if objQuestion.type=='MCQ':
            objOptionHeader=OptionHeader.objects.get(option_header_id=objQuestion.option_header_id)
            objOption=Option.objects.filter(option_header=objOptionHeader.option_header_id)
            optionText=''
            for option in objOption:
                optionText+=option.option_text + '|#|' + str(option.option_level)+'|,|'
            optionText=optionText[:-3]
            objOptionForm = OptionFrom(initial={'option_header_id':str(objOptionHeader.option_header_id),'option_text':optionText,'option_header_text':objOptionHeader.title})
            
        args['optionCreateform']=objOptionForm
        
        objQuestionForm = QuestionForm(initial={'questionID':questionId,'question':objQuestion.question,'level':objQuestion.level,'weight':objQuestion.weight,'info':objQuestion.info,'intent':objQuestion.intent,'type_text':objQuestion.type})
        args['questionCreateform']=objQuestionForm
    
    return render_to_response('Questions/CreateQuestion.html',args)
开发者ID:NikhileshKshirsagar,项目名称:AppraisalSystem,代码行数:53,代码来源:views.py

示例2: game_modify

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [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

示例3: questionCreateView

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def questionCreateView(request):
    
    args={}
    args.update(csrf(request))
    args['error']=''
    objQuestionForm = QuestionForm(request.POST or None)
    objOptionForm = OptionFrom(request.POST or None)
    if request.method == 'POST':
        if request.POST['type_text'] == 'MCQ':
 #           objOptionForm.clean_optionheadertext(sOptionHeaderText=request.POST['option_header_text'],nOptionHeaderID=request.POST['option_header_id'])
            if objQuestionForm.is_valid() and objOptionForm.is_valid():
                flag=True
            else:
                flag=False
        else:
            objOptionForm = OptionFrom()
            if objQuestionForm.is_valid():
                flag=True   
            else:
                flag=False
             
        if flag == True:
            iOptionHeaderID = 0 
            i_UserId = UserDetails.objects.get(user_id=request.session['UserID'])
            if request.POST['type_text'] == 'MCQ':
                if request.POST['option_header_id']=='0':
                    objOptionHeader = OptionHeader.objects.create(title=request.POST['option_header_text'], modified_by=i_UserId, modified_on=timezone.now())
                    iOptionHeaderID = OptionHeader.objects.latest('option_header_id')
                    objOptionForm.save(commit=False, userId=i_UserId, optionHeaderId=iOptionHeaderID)
                    
                else:
                    iOptionHeaderID = OptionHeader.objects.get(option_header_id=request.POST['option_header_id'])
            objQuestionForm.save(commit=False, userId = i_UserId, optionHeaderId = iOptionHeaderID)
            args['successMsg']="Question created successfully"
            objOptionForm = OptionFrom()
            initial = {'type_text' : request.POST['type_text']}
            objQuestionForm = QuestionForm()
            args['questionCreateform']=objQuestionForm
            args['optionCreateform']=objOptionForm
            return render_to_response('Questions/CreateQuestion.html',args)
        else:
            args['questionCreateform']=objQuestionForm
            args['optionCreateform']=objOptionForm
            return render_to_response('Questions/CreateQuestion.html',args)
    else:
        args['questionCreateform']=objQuestionForm
        args['optionCreateform']=objOptionForm
        return render_to_response('Questions/CreateQuestion.html',args)
开发者ID:NikhileshKshirsagar,项目名称:AppraisalSystem,代码行数:50,代码来源:views.py

示例4: SaveQuestionForm

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def SaveQuestionForm(request):
    if request.is_ajax():
        data = request.POST.copy()
        faq_form = QuestionForm(data)
        if faq_form.is_valid():
            saved_object = faq_form.save()
            subject = u'%s - Новый вопрос' % settings.SITE_NAME
            subject = u''.join(subject.splitlines())
            message = render_to_string(
                'faq/admin_message_template.html',
                    {
                    'saved_object': saved_object,
                    'site_name': settings.SITE_NAME,
                }
            )
            try:
                emailto = Settings.objects.get(name='workemail').value
            except Settings.DoesNotExist:
                emailto = False

            if emailto:
                msg = EmailMessage(subject, message, settings.DEFAULT_FROM_EMAIL, [emailto])
                msg.content_subtype = "html"
                msg.send()

            return HttpResponse('success')
        else:
            faq_form_html = render_to_string(
                'faq/faq_form.html',
                    {'form': faq_form}
            )
            return HttpResponse(faq_form_html)
    else:
        return HttpResponseBadRequest()
开发者ID:wd5,项目名称:sibirtrans,代码行数:36,代码来源:views.py

示例5: question_edit

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def question_edit(request, id=None):
    if id is not None:
        question = get_object_or_404(Question, pk=id)
    else:
        question = None

    categs = [(c.name.capitalize(), c.name) for c in Category.objects.all()]

    if request.method == 'POST':
        form = QuestionForm(request.POST, instance=question)
        if form.is_valid():
            newq = form.save()
            if (newq.endorsed_by is None):
                newq.endorsed_by = request.user
                newq.save()
            return HttpResponseRedirect(reverse('wouso.interface.cpanel.views.qpool_home', args = (newq.category.name,)))
    else:
        show_users = False
        if question:
            if question.category:
                if question.category.name == 'proposed':
                    show_users = True

        form = QuestionForm(instance=question, users=show_users)

    return render_to_response('cpanel/question_edit.html',
                              {'question': question,
                               'form': form,
                               'module': 'qpool',
                               'categs': categs},
                              context_instance=RequestContext(request))
开发者ID:LucianU,项目名称:wouso,代码行数:33,代码来源:views.py

示例6: qpool_edit

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def qpool_edit(request, id):
    question = get_object_or_404(Question, pk=id)
    categs = [(c.name.capitalize(), c.name) for c in Category.objects.all()]

    if request.method == 'POST':
        form = QuestionForm(request.POST, instance=question)
        if form.is_valid():
            newq = form.save()
            newq.proposed_by = request.user
            if newq.endorsed_by is None:
                newq.endorsed_by = request.user
                newq.save()
            return redirect('qpool_home', cat=newq.category.name)
        else:
            print "nevalid"
    else:
        show_users = False
        if question:
            if question.category:
                if question.category.name == 'proposed':
                    show_users = True

        form = QuestionForm(instance=question)

    return render_to_response('cpanel/qpool_edit.html',
                              {'question': question,
                               'form': form,
                               'module': 'qpool',
                               'categs': categs},
                              context_instance=RequestContext(request))
开发者ID:TobyWanKenobi,项目名称:wouso,代码行数:32,代码来源:views.py

示例7: ask

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def ask(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = form.save(commit=False)
            if request.user.is_authenticated():
                question.user = request.user
            question.save()
            return render(request, 'ask_librarian/frontend/thanks.html', {
                'question': question,
            })
    else:
        if request.user.is_authenticated():
            form = QuestionForm(
                initial={
                    'fio': request.user.last_name + u' ' + request.user.first_name,
                    'email': request.user.email,
                }
            )
        else:
            form = QuestionForm()

    return render(request, 'ask_librarian/frontend/ask.html', {
        'form': form
    })
开发者ID:isergey,项目名称:chel,代码行数:27,代码来源:views.py

示例8: add_question

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def add_question(request):
    context = {}

    settings = Settings.get_by_user(request.user)
    initial = {}

    if settings.group:
        initial["groups"] = [settings.group.id]

    if request.method == "POST":
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = form.save(commit=False)
            question.added_by = request.user
            question.save()

            revision = QuestionRevision(
                question=question, user=request.user,
                text=form.cleaned_data["body"], active=True)
            revision.save()
            return HttpResponseRedirect("/question/%s" % question.id)
    else:
        form = QuestionForm(initial=initial)

    context["form"] = form


    return r2r(request, "add_question", context)
开发者ID:Veterun,项目名称:questions,代码行数:30,代码来源:views.py

示例9: edit_question

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def edit_question(request, question_id):
    context = {}
    question = Question.objects.get(pk=question_id)
    old_revision = question.get_active_revision()

    if request.method == "POST":
        form = QuestionForm(request.POST, instance=question)
        if form.is_valid():
            form.save()
            question = form.save()
            if old_revision.text != form.cleaned_data["body"]:
                new_revision = QuestionRevision(
                    question=question, user=request.user,
                    text=form.cleaned_data["body"], active=True)
                new_revision.save()
                old_revision.active = False
                old_revision.save()
            return HttpResponseRedirect("/question/%s" % question_id)
    else:
        form = QuestionForm(instance=question, initial={
            "body": old_revision.text
        })

    context["form"] = form
    return r2r(request, "edit_question", context)
开发者ID:Veterun,项目名称:questions,代码行数:27,代码来源:views.py

示例10: questions_edit

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def questions_edit(request, instance_pk=None):
    if instance_pk is not None:
        instance = get_object_or_404(Question, pk=instance_pk)
    else:
        instance = None
    
    if request.method == 'POST':
        form = QuestionForm(request.POST, instance=instance)
        if form.is_valid():
            question = form.save(commit=False)
            question.user = request.user
            question.save()
            #
            form.save_m2m()
            # return a message
            messages.success(request, 'Question Created')
            # return a redirect
            return HttpResponseRedirect(reverse('journals:journal_today'))
    
    if request.method == 'GET':
        form = QuestionForm(instance=instance)
    
    return render_to_response('journals/questions_edit.html', RequestContext(request,{
        'form' : form,
        'instance' : instance,
    }))
开发者ID:jamiecurle,项目名称:reflection,代码行数:28,代码来源:views.py

示例11: edit_question

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def edit_question(request, question_id):
    a_question = get_object_or_404(Question, pk=question_id)
    form = QuestionForm (request.POST or None, instance = a_question)
    if form.is_valid():
        question = form.save()
        return redirect(reverse("polls:index"))

    return render (request, "polls/edit_template.html", {'form': form })
开发者ID:nestier,项目名称:tutodjango,代码行数:10,代码来源:views.py

示例12: add_question

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def add_question(request):
    form = QuestionForm()
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            form.instance.user = request.user
            form.save()
            return HttpResponseRedirect(reverse('index'))
    
    return request_response(request, 'answers/add_question.html', {'form':form})
开发者ID:seedwithroot,项目名称:django-answers,代码行数:12,代码来源:views.py

示例13: add_new_question

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def add_new_question(request):
    if request.POST:
        form = QuestionForm(request.POST)
        if form.is_valid():
            new_question = form.save()
#            return HttpResponseRedirect('/question/updated/%s/' %(new_question.id))
            return HttpResponseRedirect('/question/show/')
    else:
        form = QuestionForm()
    return render_to_response('question_model_form.html', dict(form=form))
开发者ID:shinriyo,项目名称:bucho,代码行数:12,代码来源:views.py

示例14: create

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def create(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            form.save()
            mail_admins('Someone made a question!', 'http://' + request.get_host() + '/admin/quiz/question/?state=NEW')
            return HttpResponseRedirect('/quiz/created')
    else:
        form = QuestionForm()
    return render(request, 'quiz/create.html',
        {'form':form, 'title':'Create question'})
开发者ID:knatten,项目名称:cppquiz,代码行数:13,代码来源:views.py

示例15: create

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import is_valid [as 别名]
def create(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('index')
    else:
        form = QuestionForm()
    return render_to_response('questionsandanswers/create.html',
                              {'form': form},
                              context_instance=RequestContext(request))
开发者ID:raindrop-aqua,项目名称:learn-python,代码行数:13,代码来源:views.py


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