예제 #1
0
파일: views.py 프로젝트: stabone/papillon
def answer_create(request):
    if request.method == "GET":
        return redirect(reverse_lazy('answer_form'))

    poll_id = request.POST.get('poll')
    answer_form = AnswerForm(request.POST)

    if answer_form.is_valid():
        answer_form.save()

        return redirect(reverse_lazy('poll_item', args=[poll_id]))

    return render(request, 'answer/form.html', {'form': answer_form})
예제 #2
0
파일: views.py 프로젝트: stabone/papillon
def answer_update(request):
    if request.method == "POST":
        answer_id = request.POST.get('record', '')
        poll_id = request.POST.get('poll')

        info = get_object_or_404(Answers, id=answer_id)
        answer = AnswerForm(request.POST, instance=info)

        if answer.is_valid():
            answer.save()

            return redirect(reverse_lazy('poll_item', args=[poll_id]))

    return render(request, 'answer/form.html', {'form': answer})
예제 #3
0
def answer(req):
	id_q = req.GET.get('id_q')
	a_list = Answer.objects.filter(question_id=id_q)
	paginator = Paginator(a_list, 3)

	page = req.GET.get('page')
	try:
		answers = paginator.page(page)
	except PageNotAnInteger:
		answers = paginator.page(1)
	except EmptyPage:
		answers = paginator.page(paginator.num_pages)
	question = Question.objects.get(id=id_q)
	if req.user.is_authenticated:
		if req.method == 'POST':
			form = AnswerForm(req.POST, profile=req.user.profile,question=id_q)
			if form.is_valid():
				form.save()
				return HttpResponseRedirect(req.META.get('HTTP_REFERER','/'))
		else:
			form = AnswerForm()
		return render(req,'answer.html', {'form':form, 'answers': answers, 'question': question})
	else:
		return render(req,'answer.html', { 'answers': answers, 'question': question})