Пример #1
0
def save_answer(request):
    user = request.user
    if request.method == 'POST' and user.is_authenticated():
        form = AnswerForm(request.POST)
        form.user = user
        if form.is_valid():
            answer = form.save()
            return HttpResponseRedirect(reverse('question_details', kwargs={'question_id': answer.question.id}))

    return HttpResponseRedirect(reverse('login'))
Пример #2
0
def answer_add(request, question_id):
	if request.method == "POST":
		form = AnswerForm(request.POST)
		form.user=request.user
		if form.is_valid():
			answer = form.save()
			return redirect('question_details', answer.question.id)
	else:
		form = AnswerForm()
	return render(request, 'qa/question_details.html', {	
		'form': form,
	})
Пример #3
0
def answer(request):
    if request.method == 'POST':
        answer = AnswerForm(request.POST)
            
        if answer.is_valid():
            answer.user = request.user 
            answer.save()
            
        next = request.GET.get('next', '/')

        return HttpResponseRedirect(next)
        
    raise Http404
Пример #4
0
def answer(request):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            if request.user.is_anonymous():
                return HttpResponseRedirect('/login')

            form.user = request.user
            answer = form.save()
            url = reverse('question', args=[answer.question.id])
            return HttpResponseRedirect(url)

    return HttpResponseRedirect('/')
Пример #5
0
def answer(request):
    if request.method == 'POST':
        answer = AnswerForm(request.POST)

        if answer.is_valid():
            answer.user = request.user
            answer.save()

        next = request.GET.get('next', '/')

        return HttpResponseRedirect(next)

    raise Http404