本文整理汇总了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,})
示例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())
示例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)
示例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
})
示例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', '/'))
示例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()
示例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,
})
示例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'))
示例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
})
示例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,
})
示例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})
示例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
})