当前位置: 首页>>代码示例>>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;未经允许,请勿转载。