Exemple #1
0
def comment(request, answer_num):
    c = {}
    form = CommentForm(request.POST)
    answer = get_object_or_404(Answer, pk=answer_num)
    site = get_object_or_404(Site, pk=settings.SITE_ID)
    try:
        comment = form.save(commit=False)
        comment.user = request.user
        comment.content_object = answer
        comment.submit_date = datetime.now()
        comment.site = site
        comment.save()
    except ValueError:
        c['comment_error'] = True
    return redirect(answer.question)
Exemple #2
0
def question(request, question_id=0):
    """
    viewing the question
    """
    if int(question_id) == 0:
        HttpResponseRedirect(reverse('home'))

    q = get_object_or_404(Question, id=question_id)

    # Comment Form
    if request.method == "POST":
        if not request.user.is_authenticated():
            return HttpResponseRedirect(reverse('login_url'))

        commentform = CommentForm(request.POST)
        if commentform.is_valid():
            _commentform = commentform.save(commit=False)
            _commentform.question = q
            _commentform.user = request.user
            _commentform.save()

            return HttpResponseRedirect(
                reverse(
                    'view_question',
                    kwargs={'question_id': question_id}))
    elif request.method == "GET":
        commentform = CommentForm()

    return render(request, "question.html", {
        'question': q,
        'commentform': commentform,
    })
def question(request, question_id=0):
    """
    viewing the question
    """
    if int(question_id) == 0:
        HttpResponseRedirect(reverse("home"))

    q = get_object_or_404(Question, id=question_id)

    # Comment Form
    if request.method == "POST":
        commentform = CommentForm(request.POST)
        if commentform.is_valid():
            _comment = commentform.save(commit=False)
            _comment.user = request.user
            _comment.question = q
            _comment.save()

            return HttpResponseRedirect(reverse("view_question", kwargs={"question_id": question_id}))

    elif request.method == "GET":
        commentform = CommentForm()

    return render(request, "question.html", {"question": q, "commentform": commentform})