예제 #1
0
def single_question(request, id, page='1'):
    question = get_object_or_404(Question, pk=id)
    answers = question.answer_set.all()
    answer_list = paginator_foo.pagination(answers, 4, page)
    answer_list.paginator.baseurl = "/question/id" + id + "/"

    last_page_num = int((answers.count() + 1) / 4 + 1)

    if request.method == "POST":
        answer_form = AnswerForm(request.POST)
        if answer_form.is_valid():
            answer = answer_form.save(question, request.user)
            return HttpResponseRedirect(
                reverse('question',
                        kwargs={
                            'id': question.id,
                            'page': last_page_num
                        }) + '#answer_' + str(answer.id))
    else:
        answer_form = AnswerForm()
    return render(
        request,
        'question.html',
        {
            "question": question,
            "answers": answer_list,
            "new_question": True,
            "form": answer_form
        },
    )
예제 #2
0
def hot_questions(request, page='1'):
    myquestions = Question.objects.hot()
    question_list = paginator_foo.pagination(myquestions, 5, page)
    question_list.paginator.baseurl = "/hot/"
    return render(
        request,
        'hot_questions.html',
        {"questions": question_list},
    )
예제 #3
0
def index(request, page='1'):
    myquestions = Question.objects.newest()
    question_list = paginator_foo.pagination(myquestions, 5, page)
    question_list.paginator.baseurl = "/"
    return render(
        request,
        'index.html',
        {"questions": question_list},
    )
예제 #4
0
def tag(request, tag, page='1'):
    myquestions = Question.objects.tag_search(tag)
    question_list = paginator_foo.pagination(myquestions, 5, page)
    question_list.paginator.baseurl = "/tag/" + tag + "/"
    return render(
        request,
        'tag.html',
        {
            "questions": question_list,
            'tag': tag
        },
    )
예제 #5
0
def profile(request, user_name, page='1'):
    myquestions = Question.objects.user_questions(user_name)
    profile = Profile.objects.get_by_name(user_name)
    question_list = paginator_foo.pagination(myquestions, 5, page)
    question_list.paginator.baseurl = "/profile/" + profile[
        0].user.username + "/"
    return render(
        request,
        'profile.html',
        {
            "questions": question_list,
            "profile": profile[0]
        },
    )