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


Python AnswerForm._user方法代碼示例

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


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

示例1: answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import _user [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 _user [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: answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import _user [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

示例4: question_details

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import _user [as 別名]
def question_details(request, qid, *args, **kwargs):
    question = get_object_or_404(Question, id=qid)
    form = AnswerForm(initial={'question': qid})
    form._user = request.user
    return render(request, 'question_details.html', {
        'question': question,
        'form': form
        })
開發者ID:krkmetal,項目名稱:webtech-project,代碼行數:10,代碼來源:views.py

示例5: add_answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import _user [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

示例6: answer_question

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import _user [as 別名]
def answer_question(request):
    form = AnswerForm(request.POST)
    form._user = request.user
    if form.is_valid():
        answer = form.save()
        url = answer.question.get_url()
        return HttpResponseRedirect(url)
    else:
        return HttpResponseBadRequest()
開發者ID:krkmetal,項目名稱:webtech-project,代碼行數:11,代碼來源:views.py

示例7: answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import _user [as 別名]
def answer(request):
    form = AnswerForm(request.POST)
    question = get_object_or_404(Question, pk=form.question_id)
    if form.is_valid():
        form._user = request.user
        answer = form.save()
        url = answer.get_url()
        return HttpResponseRedirect(url)
    return render(request, 'qa/question.html', {
        'question': question,
        'form': form,
    })
開發者ID:Nalie,項目名稱:stepic-web-technologies,代碼行數:14,代碼來源:views.py

示例8: answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import _user [as 別名]
def answer(request, *args, **kwargs):
	if (request.method == "GET"):
		return HttpResponseRedirect("/")
	
	answer = AnswerForm(request.POST)
	answer._user = request.user
	if answer.is_valid():
		answer = answer.save(HTTP_REFERER = request.META.get('HTTP_REFERER'))
		url = answer.get_absolute_url()
		return HttpResponseRedirect(url)
	else:
		return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
開發者ID:luchnck,項目名稱:teststep,代碼行數:14,代碼來源:views.py

示例9: answer_add

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import _user [as 別名]
def answer_add(request):
    if request.method == "POST":
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid(): 
            answer = form.save()
            url = answer.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm()
    return render(request, 'qa/answer_add.html', {
        'form': form
    })     
開發者ID:Nick-Gorev,項目名稱:stepic_web_project,代碼行數:15,代碼來源:views.py

示例10: answer

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import _user [as 別名]
def answer(request):
    if request.method == 'POST':
        if request.user.is_authenticated():
            form = AnswerForm(request.POST)
            form._user = request.user
            if form.is_valid():
                answer = form.save()
                question = answer.question
                url = question.get_url()
                return HttpResponseRedirect(url)
        else:
            return HttpResponseRedirect(default_url)
    else:
        form = AnswerForm()
    return render(request, 'answer_form.html',{
            'form':form,
        })
開發者ID:mikronavt,項目名稱:stepic_web_01,代碼行數:19,代碼來源:views.py

示例11: question

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import _user [as 別名]
def question(request, pk_question):
    try:
        gs = Question.objects.get(id=pk_question)
    except Question.DoesNotExist:
        raise Http404

    if request.method == "POST":
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            _ = form.save()
            redirect_url = gs.get_url()
            return HttpResponseRedirect(redirect_url)
    else:
        form = AnswerForm(initial={'question': gs.id})

    return render(
        request, 'question.html',
        {'question': gs, 'form': form})
開發者ID:mISCLETI,項目名稱:stepic_web_project,代碼行數:21,代碼來源:views.py

示例12: post

# 需要導入模塊: from forms import AnswerForm [as 別名]
# 或者: from forms.AnswerForm import _user [as 別名]
def post(request, *args, **kwargs):
        post_id  = args[0]
	#post_url = '/answer/?question='+str(post_id)
	post_url = '/question/'+str(post_id)+'/'
	try:
		post = Question.objects.get(id=post_id)
	except Question.DoesNotExist:
		raise Http404
	if request.method == "POST":
                form = AnswerForm(request.POST)
		form._user = request.user 
		form._question = args[0] 
		if form.is_valid():
                        post = form.save()
                        #url = post.get_url()
                        return HttpResponseRedirect(post_url)
        else:
        	form = AnswerForm()
	return render(request, 'tpl_post.html', {
       	'post': post,
       	'answers' : post.answer_set.all(),
       	'form' : form,
	'post_url' : post_url
       	})
開發者ID:PHantoMby,項目名稱:3,代碼行數:26,代碼來源:views.py


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