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


Python QuestionForm.save方法代码示例

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


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

示例1: edit_question

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

示例2: add_question

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

示例3: create

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

示例4: create

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

示例5: create

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import save [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/?published__exact=0"
            )
            return HttpResponseRedirect("/quiz/created")
    else:
        form = QuestionForm()
    return render_to_response("quiz/create.html", {"form": form}, context_instance=RequestContext(request))
开发者ID:stic,项目名称:cppquiz,代码行数:14,代码来源:views.py

示例6: edit

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

示例7: edit_question

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import save [as 别名]
def edit_question(request, question_id):

    question_to_edit = Question.objects.get(id=question_id)

    if request.method == 'POST':
        form = QuestionForm(request.POST, instance=question_to_edit)

        if form.is_valid():
            form.save()        
            return questions(request)
    else:
        form = QuestionForm(instance=question_to_edit)

    return render(request, 'edit_questions.html', {'form' : form})
开发者ID:Rogergonzalez21,项目名称:questionsGame,代码行数:16,代码来源:views.py

示例8: editQuestion

# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import save [as 别名]
def editQuestion(request, project_id, question_id):
	p = get_object_or_404(Project, pk = project_id, owner = request.user)
	q = get_object_or_404(Question, pk = question_id)
	
	#answer = Answer.objects.get(pk=p)
	if request.method == 'POST': # If the form has been submitted...
		form = QuestionForm(request.POST, instance = q) # A form bound to the POST data
		if form.is_valid(): # All validation rules pass
			form.save()			
			return HttpResponseRedirect('/flow/' + project_id +'/#' + question_id) # Redirect after POST
	else:
		form = QuestionForm(instance=q) # A form initiated with the question data
		variables = RequestContext(request, { 'form': form,	 'url_project' : p, 'url_question' : q })
		return render_to_response('flow/editQuestion.html', variables)
开发者ID:Seppala,项目名称:Learness,代码行数:16,代码来源:views.py

示例9: game_modify

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

示例10: questionCreateView

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

示例11: question_edit

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

示例12: ask

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

示例13: questions_edit

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

示例14: qpool_edit

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

示例15: SaveQuestionForm

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


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