Пример #1
0
def answer_add(request):
   if request.method == 'POST': 
     form = AnswerForm(request.POST)
     form._user = request.user
     if form.is_valid():
       form._user = request.user 
       post = form.save()
       #url = post.get_url()
       return HttpResponseRedirect(reverse('question', args=[post.question.id]))
   return HttpResponseRedirect('/')
Пример #2
0
def answer(request, *args, **kwargs):
    form = AnswerForm(request.POST)
    form._user = request.user
    if form.is_valid():
        answer = form.save()
        return HttpResponseRedirect(answer.question.get_url())
    return Http404
Пример #3
0
def question(request, pk):
    def render_with_answers():
        try:
            answers = Answer.objects.filter(question_id=pk)
        except Answer.DoesNotExist:
            answers = None
        return render(request, 'question.html', {
            'question': question_page,
            'answers': answers,
            'form': form,
        })

    question_page = get_object_or_404(Question, id=pk)
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            form.save()
            url = question_page.get_absolute_url()
            return HttpResponseRedirect(url)
        else:
            form.cleaned_data['question'] = pk
            return render_with_answers()
    else:
        form = AnswerForm(initial={'question': pk})
        return render_with_answers()
Пример #4
0
def question_page(request, **kwargs):
    logger = logging.getLogger(__name__)
    logger.debug('question_page')

    num = int(kwargs.get('num'))
    question = get_object_or_404(Question, id=num)

    if request.method == 'POST':
        if request.user.is_authenticated:
            form = AnswerForm(request.POST)
            form._user = request.user
            if form.is_valid():
                answer = form.save()
                url = question.get_url()
                logger.debug('url: {}'.format(url))
                newform = AnswerForm(initial={'question': question.pk})
                return render(
                    request, 'question.html', {
                        'question': question,
                        'title': question.title,
                        'answers': Answer.objects.filter(question=question)[:],
                        'form': newform,
                    })
        else:
            return HttpResponseRedirect('/login/')
    else:
        form = AnswerForm(initial={'question': question.pk})
        return render(
            request, 'question.html', {
                'question': question,
                'title': question.title,
                'answers': Answer.objects.filter(question=question)[:],
                'form': form,
            })
Пример #5
0
def question_detail(request, question_id):
    """One question page. 
    This page displays the title, text of the question 
    and all the answers to this question.
    
    """
    question = get_object_or_404(Question, pk=question_id)
    answers = question.answer_set.all()
    form = AnswerForm(request.POST)

    if request.method == 'POST' and form.is_valid():
        form._user = request.user
        answers = form.save()
        url = question.get_url()
        return HttpResponseRedirect(url)
    else:
        form = AnswerForm(initial={'question': question_id})

    return render(
        request, 'question_detail.html', {
            'questions': question,
            'answers': answers,
            'user': request.user,
            'form': form,
        })
Пример #6
0
def answer_add(request):
    answer_form = AnswerForm(request.POST)
    answer_form._user = request.user
    if answer_form.is_valid():
        answer = answer_form.save()        
    quest_id = request.POST['question']    
    return HttpResponseRedirect(reverse('question', args=[quest_id])) 
Пример #7
0
def question(
    request,
    num,
):
    try:
        q = Question.objects.get(id=num)
    except Question.DoesNotExist:
        raise Http404
    if request.method == "POST":
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            _ = form.save()
            url = q.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm(initial={'question': q.id})

    return render(
        request, 'question.html', {
            'question': q,
            'form': form,
            'user': request.user,
            'session': request.session,
        })
Пример #8
0
def D_question(request, q_id):
    try:
        question = Question.objects.get(pk=q_id)
    except Question.DoesNotExist:
        raise Http404
    answers = Question.objects.get_answers(question)[:]
    user = request.user
    if user.is_authenticated():
        if request.method == 'POST':
            form = AnswerForm(request.POST)
            form._user = request.user
            if form.is_valid():
                answer = form.save(question)
                url = answer.question.get_url()
                return HttpResponseRedirect(url)
        else:
            form = AnswerForm(initial={'question': q_id})
        return render(request, 'D_question.html', {
            'form': form,
            'question': question,
            'answers': answers,
        })
    else:
        return render(request, 'D_question_anon.html', {
            'question': question,
            'answers': answers,
        })
Пример #9
0
def question(request, slug):
    try:
        pk = int(slug)
    except ValueError:
        raise Http404

    try:
        q = Question.objects.get(pk=pk)
    except ObjectDoesNotExist:
        raise Http404

    if request.method == 'POST':
        if request.user.is_authenticated is False:
            return HttpResponseForbidden()
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/question/%s/' % pk)
    else:
        form = AnswerForm(initial={'question': pk})

    answers = Answer.objects.filter(question=q).all()
    return render(request,
                  'question_template.html',
                  {'q': q,
                   'form': form,
                   'answers': answers})
Пример #10
0
def answer(request):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            answer = form.save()
            return HttpResponseRedirect(answer.question.get_url())
    return question(request,form.cleaned_data["question_id"],form = form)
Пример #11
0
def answer(request, *args, **kwargs):
    if request.method == "POST":
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            ans = form.save()
            url = ans.redir_url()
            return HttpResponseRedirect(url)
Пример #12
0
def answerHandle(request):
    answer = AnswerForm(request.POST)
    answer._user = request.user
    if answer.is_valid():
        answer = answer.save()
        return HttpResponseRedirect('/question/' + str(answer.question_id))

    return HttpResponseRedirect('/question/' + str(answer.get_question()) )
Пример #13
0
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.question.get_absolute_url()
            return HttpResponseRedirect(url)
    HttpResponseRedirect('/')
Пример #14
0
def question_answer(request):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            answer = form.save()
            url = reverse('question_detail', args=[answer.question.id])
            return HttpResponseRedirect(url)
    return HttpResponseRedirect('/')
Пример #15
0
def add_answer(request):
    if request.method == "POST":
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            answer_obj = form.save()
            question_obj = answer_obj.question
            url = question_obj.get_url()
            return HttpResponseRedirect(url)
Пример #16
0
def question_answer(request):
	if request.method == 'POST':
		form = AnswerForm(request.POST)
		if form.is_valid():
			form._user = request.user
			answer = form.save()
			url = reverse('question', args=[answer.question.id])
			return HttpResponseRedirect(url)
	return HttpResponseRedirect('/')	
Пример #17
0
def answer(request, *args, **kwargs):
    form = AnswerForm(request.POST)
    if request.user.is_authenticated():
            form._user = request.user
    if form.is_valid():
        a = form.save()
        return HttpResponseRedirect('/question/' + str(a.question.pk) + '/')
    else:
        return HttpResponseRedirect('/question/' + str(a.question.pk) + '/?err=1')    
Пример #18
0
def answer(request):
    form = AnswerForm(request.POST)
    if form.is_valid():
        form._user = request.user
        question = form.save()
        url = question.get_url()
        return HttpResponseRedirect(url)
    question = Question.objects.get(pk=form.question)
    return render(request, 'question.html', {'quest': question, 'form': form})
Пример #19
0
 def post(self,request, pk):
     bound_form=AnswerForm(request.POST)
     qs=Question.objects.get(pk=pk)
     if bound_form.is_valid():
         bound_form._user=request.user
         bound_form.save()
         return redirect(qs)
     else:
         return render (request, 'qa/question_detail.html', context={'form':bound_form,'question':qs})
Пример #20
0
def question_ans(request):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            answer = form.save()
            url = answer.get_url()
            return HttpResponseRedirect(url)
    return HttpResponseRedirect('/')
Пример #21
0
def answer(request):
    form = AnswerForm(request.POST)
    if request.user.is_authenticated():
        form._user = request.user
    if form.is_valid():
        a = form.save()
        return HttpResponseRedirect('/question/' + str(a.question.pk) + '/')
    else:
        return HttpResponseRedirect('/question/' + str(a.question.pk) + '/?err=1')
Пример #22
0
def answer_add(request):
    if request.method == 'GET':
        return HttpResponseRedirect('/', request)

    form = AnswerForm(request.POST)
    if form.is_valid():
        form._user = request.user
        answer = form.save()
        return HttpResponseRedirect(answer.get_url())
    return HttpResponseRedirect('/question/%s/' % request.POST['question'])
Пример #23
0
def answer_add(request):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            post = form.save()
            # url = post.get_url()
            return HttpResponseRedirect(
                reverse('question', args=[post.question.id]))
    return HttpResponseRedirect('/')
def answer(request):
    user = request.user
    if request.method == "POST":
        if not user.is_authenticated():
            raise Http404
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = user
            answer = form.save()
            url = '/question/' + form.question
            return HttpResponseRedirect(url)
Пример #25
0
def answer(request):
    form = AnswerForm(request.POST)
    if form.is_valid():
	form._user = request.user
	question = form.save()
	url = question.get_url()
	return HttpResponseRedirect(url)
    question = Question.objects.get(pk=form.question)
    return render(request, 'question.html', {
	'quest': question, 'form': form
    })
Пример #26
0
def answer_add(request):
	if request.method == "POST":
		form = AnswerForm(request.POST)
		#print request.user
		form._user = request.user
		if form.is_valid():
			#print form.cleaned_data
			answer = form.save()
			#print answer.text
			#print answer.author
			url = answer.get_url()
			return HttpResponseRedirect(url)
Пример #27
0
def question(request, question_id):
    qq = get_object_or_404(Question, pk=question_id)
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            a = form.save()
            url = '/question/%d/' % a.question.id
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm()
    return render(request, 'qa/question.html', {'q': qq, 'form': form})
Пример #28
0
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})
Пример #29
0
def answer_add(request, question_id):
    question = Question.objects.get(id=question_id)
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            answer = form.save()
            url = question.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm()
    return render(request, 'question_details.html', {
        'form': form,
    })
Пример #30
0
def vq123(request,dd):
    question=Question.objects.get(id=dd)
    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(initial={'question': question.id})
    return render(request,'question.html', {
          'form': form,
    })
Пример #31
0
def answer(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:
            answer = form.save()
            url = answer.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm()
Пример #32
0
def detail_page(request, pk):
    question = get_object_or_404(Question, pk=pk)
    if request.method == 'GET':
        form = AnswerForm({'question_id': question.pk})
    elif request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            form.save()
            return redirect('detail', pk=question.pk)
    return render(request, 'qa/detail.html', {
        'question': question,
        'answers': question.answer_set.all(),
        'form': form
    })
Пример #33
0
def add_answer(request):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            answer = form.save()
            url = answer.get_absolute_url()
            return HttpResponseRedirect(url)
        else:
            try:
                form = AnswerForm()
                url = '/question/%s/' % request.POST['question']
                return HttpResponseRedirect(url)
            except:
                return render("200")
Пример #34
0
def get_question(request, question_id):
    question = get_object_or_404(Question, id=question_id)
    if request.method == "POST":
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            answer = form.save()
            url = question.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm(initial={'question': question.id})
    return render(request, 'question.html', {
        'q': question,
        'form': form,
    })
Пример #35
0
def question(request, *args, **kwargs):
    try:
        q = Question.objects.get(id=kwargs['num'])
    except Question.DoesNotExist:
        raise Http404

    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            answer = form.save()
            url = q.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm(initial={'question': q.id})
    return render(request, 'question.html', {'question': q, 'form': form})
Пример #36
0
def question(request, num):
    try:
        q = Question.objects.get(id=num)
    except Question.DoesNotExist:
        raise Http404
    if request.method == "POST":
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            post = form.save()
            url = post.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm()
    a = Answer.objects.all().filter(question=q)
    return render(request, 'question.html', {'q': q, 'a': a, 'form': form})
Пример #37
0
def question(request, question_id):    
    question = get_object_or_404(Question, pk=question_id)
    answers = Answer.objects.filter(question=question_id)
    if request.method == "POST":
        form = AnswerForm(request.POST)
        if form.is_valid():
            form.clean()
            form._user = request.user
            form.save()
            HttpResponseRedirect('/question/%s/' % question_id)
    else:
        form = AnswerForm()
    return render(request, 'qa/question.html', {
        'question': question,
        'answers': answers,
        'form': form
    })
Пример #38
0
def postAnswer(request, *args, **kwargs):
    if request.method == 'POST':
       form = AnswerForm(request.POST)
       form._user = request.user
       if form.is_valid():
          answer = form.save()
          question = Question.objects.get(id = form.cleaned_data['question'])
          url = question.get_url()
          return HttpResponseRedirect(url)
    #   return HttpResponse('answer form post') 
    else:
       form = AnswerForm()
    
    return render( request,
                   'qa/AnswerOnlyForm.html',
                   {
                     'form':form,
                     })           
Пример #39
0
def question_details(request, id):
    question = get_object_or_404(Question, id=id)
    if request.method == "POST":
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            answer = form.save()
            url = question.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm(initial={'question': question.id})
    return render(
        request, 'question_details.html', {
            'question': question,
            'form': form,
            'user': request.user,
            'session': request.session,
        })
Пример #40
0
def question(request, number):
    q = get_object_or_404(Question, id=number)
    url = q.get_url()
    answers = Answer.objects.filter(question=q)
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        form._question = q
        if form.is_valid():
            ans = form.save()
            return HttpResponseRedirect(url)
    form = AnswerForm()
    return render(request, 'qa/question.html', {
        'question': q,
        'answers': answers,
        'form': form,
        'action': url
    })
Пример #41
0
def question(request, QID):
    quest = get_object_or_404(Question, id=QID)
    answ = Answer.objects.filter(question=QID).order_by('-id')
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            answer = form.save()
            url = quest.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm()
    context = {
        'title': 'Question page',
        'question': quest,
        'answ': answ,
        'form': form,
    }
    return render(request, 'question.html', context)
Пример #42
0
def quest(request, id):
    qu = get_object_or_404(Question, id=id)
    try:
        an = Answer.objects.filter(question=qu)
    except Answer.DoesNotExist:
        an = None
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        if form.is_valid():
            ans = form.save(id)
            return HttpResponseRedirect(ans.get_url())
    else:
        form = AnswerForm(initial={'text': '', 'question': id})
    return render(request, 'qa/question.html', {
        'qu': qu,
        'an': an,
        'form': form
    })
Пример #43
0
def question_by_id(request, id):
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = get_user_by_ssid(request)
        if form.is_valid():
            post = form.save(id)
            url = '/question/{id}'.format(id=id)
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm(initial={'question': id})

       
    question = get_object_or_404(Question, id = id)
    answers = Answer.objects.filter(question=question)
    return render(request, 'qa/question.html', {
        'question': question,
        'answers': answers,
        'form' : form, 
        })
Пример #44
0
def question(request, num,):
    try:
        q = Question.objects.get(id=num)
    except Question.DoesNotExist:
        raise Http404
    if request.method == "POST":
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            _ = form.save()
            url = q.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm(initial={'question': q.id})

    return render(request, 'question.html', {'question': q,
                                             'form': form,
                                             'user': request.user,                                           
                                             'session': request.session, })
Пример #45
0
Файл: views.py Проект: zmozg/web
def single_question(request, pk):
    question = get_object_or_404(Question, pk=pk)
    answers = question.answer_set.all()
    if request.method == "POST":
        form = AnswerForm(request.POST, initial={'question': pk})
        if form.is_valid():
            form._user = request.user
            form.save()
        else:
            return HttpResponse('200')
        answers = question.answer_set.all()
        url = question.get_url()
        return HttpResponseRedirect(url)
    else:
        form = AnswerForm(initial={'question': pk})
    return render(request, 'qa/question.html', {
        'question': question,
        'answers': answers,
        'form': form,
    })
Пример #46
0
def question_page(request, pk):
    try:
        quest = Question.objects.get(id=pk)
    except Question.DoesNotExist:
        raise Http404
    ans = Answer.objects.filter(question_id=pk)
    if request.method == "POST":
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            form.save()
            url = quest.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm(initial={'question': quest.id})
    return render(request, 'question_with_answers.html', {
        'question': quest,
        'answers': ans,
        'form': form,
    })
Пример #47
0
def detail(request, pk):
    question = get_object_or_404(Question, pk=pk)
    answers = question.answer_set.all()
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            form._user = request.user
            form.save()
            return HttpResponseRedirect(
                reverse('qa:detail', kwargs={'pk': pk})
            )
    else:
        form = AnswerForm(initial={'question': question})
    return render(
        request,
        'qa/detail.html',
        {'question': question,
         'answers': answers,
         'form': form}
    )
Пример #48
0
def question(request, id):
    try:
        question = Question.objects.get(id = id)
        answers = question.answer_set.all()
        if request.method == "POST":
            form = AnswerForm(request.POST)
            form._user = request.user
            if form.is_valid():
                answer = form.save()
                url = question.get_url()
                return HttpResponseRedirect(url)
        else:
            form = AnswerForm()
    except Question.DoesNotExist:
        raise Http404

    return render(request, 'question.html', {
        'question' : question,
        'answers' : answers,
        'form' : form,
    })