當前位置: 首頁>>代碼示例>>Python>>正文


Python AnswerForm.save方法代碼示例

本文整理匯總了Python中forms.AnswerForm.save方法的典型用法代碼示例。如果您正苦於以下問題:Python AnswerForm.save方法的具體用法?Python AnswerForm.save怎麽用?Python AnswerForm.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在forms.AnswerForm的用法示例。


在下文中一共展示了AnswerForm.save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def answer(request, *args, **kwargs):
    quest_id = kwargs['pk']
#    print 'in answer'

    if request.method == "POST":
#        print 'post on answer'
        form = AnswerForm(request.POST)
        if request.user.is_authenticated():
            form._user=request.user
        if form.is_valid():
            form.save()
            redir_url = '/question/'+str(quest_id)+'/'
            return HttpResponseRedirect(redir_url) 
    else:
#        print 'get on answer'
        try:
            question = Question.objects.get(id=quest_id)
#            print 'from anser'
#            user = request.user
#            print user
            form=AnswerForm(initial={'question': question})
#            form = AnswerForm(initial={'question': question, 'author': user})    
            answers = question.answer_set.all()        
            ans= (answers.values('text'))
            l=[l['text'] for l in ans]
            #answers =str(answers).decode('utf8')
#               print repr(answers).decode("unicode_escape")        
        except Question.DoesNotExist:
            raise Http404
    return render(request, 'question_old.html', {'form': form, 'quest_title': question.title, 'quest_text': question.text, 'answers':l,})
開發者ID:k549at,項目名稱:stepic_web_project,代碼行數:32,代碼來源:views.py

示例2: answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def answer(request, quest):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(quest.get_url())
開發者ID:bgv26,項目名稱:WebTech,代碼行數:9,代碼來源:views.py

示例3: question

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def question(request, quest_id):
    quest = get_object_or_404(Question, id=quest_id)
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form.set_author(request.user)
        if form.is_valid():
            form.save()
    else:
        form = AnswerForm()
    return render(request, "question_detail.html", {'question': quest, 'form': form})
開發者ID:bgv26,項目名稱:WebTech,代碼行數:12,代碼來源:views.py

示例4: editAnswer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def editAnswer(request, project_id, question_id, answer_id):
	p = get_object_or_404(Project, pk = project_id, owner = request.user)
	q = get_object_or_404(Question, pk = question_id)
	a = get_object_or_404(Answer, pk = answer_id)
	#answer = Answer.objects.get(pk=p)
	if request.method == 'POST': # If the form has been submitted...
		form = AnswerForm(request.POST, instance = a) # A form bound to the POST data
		if form.is_valid(): # All validation rules pass
			form.save()			
			return HttpResponseRedirect('/flow/' + project_id + '/' + question_id + '/#' + question_id) # Redirect after POST
	else:
		form = AnswerForm(instance=a) # An unbound form
		variables = RequestContext(request, { 'form': form,	 'url_project' : p, 'url_question' : q, 'url_answer' : a})
		return render_to_response('flow/editanswer.html', variables)
開發者ID:Seppala,項目名稱:Learness,代碼行數:16,代碼來源:views.py

示例5: answer_question

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def answer_question(request, question_id):
    question = get_object_or_404(Question, id=question_id)
    form = AnswerForm()
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            if request.user.is_authenticated():
                form.instance.user = request.user
            form.instance.question = question
            form.instance.ip = request.META['REMOTE_ADDR']
            form.save()
            return HttpResponseRedirect(reverse('view_question', args=[question_id]))

    return request_response(request, 'answers/answer_question.html',
                            {'form': form, 'question': question})
開發者ID:seedwithroot,項目名稱:django-answers,代碼行數:17,代碼來源:views.py

示例6: question_details

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def question_details(request, id):
    try:
        question = Question.objects.get(pk=id)
    except Question.DoesNotExist:
        raise Http404
    if request.method == "POST":
        user = request.user
        if not user.is_authenticated():
            return HttpResponseRedirect('/login/')
        form = AnswerForm(request.POST)
        form.setUser(user)
        if form.is_valid():
            answer = form.save()
            question = answer.question
            url = question.get_absolute_url()
            return HttpResponseRedirect(url)
    else:
        default_data = {'question': question.id}
        form = AnswerForm(initial=default_data);
    answers = Answer.objects.filter(question=question).order_by('-added_at')
    return render(request, 'question.html', {
                  'question': question,
                  'answers': answers,
                  'form': form,
    })
開發者ID:denproger,項目名稱:stepic_web_project,代碼行數:27,代碼來源:views_question.py

示例7: answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def answer(request):
    form = AnswerForm(request.POST)
    form._user = request.user
    if form.is_valid():
        answer = form.save()
        url = answer.get_question_url()
        return HttpResponseRedirect(url)
開發者ID:SvetlanaKantola,項目名稱:stepic_web_project,代碼行數:9,代碼來源:views.py

示例8: answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def answer(request):
    form = AnswerForm(request.POST)
    if form.is_valid():
        a = form.save()
        url = '/question/%s/' % a.question.pk
        return HttpResponseRedirect(url)
    return HttpResponseRedirect('/answer/')
開發者ID:ky4web,項目名稱:stepic,代碼行數:9,代碼來源:views.py

示例9: newanswer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def newanswer(request):
	url = '/question/'
	if request.method == "POST":
		newanswer = AnswerForm(request.POST)
		if newanswer.is_valid():
			url = url + str(newanswer.save()) + '/'
	return HttpResponseRedirect(url) 
開發者ID:AleksStek,項目名稱:stepic-web,代碼行數:9,代碼來源:views.py

示例10: create_answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def create_answer(request, article_id):
	a = Article.objects.get(id=article_id)
	
	if request.POST:
		f = AnswerForm(request.POST)
		if f.is_valid():
			c = f.save(commit=False)
			c.pub_date = timezone.now()
			c.related_article = a
			c.posted_by = request.user
			c.save()
			a.num_answers += 1
			a.answers.add(c)
			a.save()			
			
			return HttpResponseRedirect('/get/%s' % article_id)
	else:
		f = CommentForm()
	
	args = {}
	args.update(csrf(request))
	args['article'] = a
	args['form'] = f
	
	return render(request, 'add_comment.html', args)
開發者ID:Radicis,項目名稱:asktag,代碼行數:27,代碼來源:views.py

示例11: answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def answer(request):
    form = AnswerForm(request.POST)
    if form.is_valid():
        answer = form.save(commit=False)
        answer.author = request.user
        answer.save()
        return redirect(answer.question)
開發者ID:milton14,項目名稱:webStepic,代碼行數:9,代碼來源:views.py

示例12: newanswer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def newanswer (request, *args, **kwargs):
    form = AnswerForm(request.POST)
    form.user = request.user
    if form.is_valid():
        question_id = form.save()
        return HttpResponseRedirect(reverse('question', kwargs={'question_id': question_id}))
    else:
        return question(request, **{'form' : form, 'question_id': form.get_question_id()})
開發者ID:smartybit,項目名稱:stepic_webtech1,代碼行數:10,代碼來源:views.py

示例13: answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def answer(request, *args, **kwargs):
    if request.method == "POST":
        form = AnswerForm(request.POST)
        if form.is_valid():
            form.cleaned_data['author'] = request.user
            a = form.save()
            return HttpResponseRedirect(a.question.get_absolute_url())
        return render(request, "form.html", {'url':request.path, 'form':form})
開發者ID:a2151257-2,項目名稱:web,代碼行數:10,代碼來源:views.py

示例14: answer_add

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def answer_add(request):
    if request.method == 'POST':
	form = AnswerForm(request.POST)
	if form.is_valid():
	    answer = form.save()
	    url = question.get_url()
	    return HttpResponseRedirect(reverse(url))
    return HttpResponseRedirect('/')
開發者ID:igorlutsenko,項目名稱:stepic_web_project_6,代碼行數:10,代碼來源:views.py

示例15: add_answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import save [as 別名]
def add_answer(request):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            answer = form.save()
            return HttpResponseRedirect(answer.get_url())
    return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
開發者ID:AbiGeuS2,項目名稱:webstepicrepo2,代碼行數:10,代碼來源:views.py


注:本文中的forms.AnswerForm.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。