def hot(request, page=None): questions = Question.objects.hot() questions_on_page = paginate(questions, request, 10, page) return render(request, 'ask/hot.html', { 'questions': questions_on_page, 'page': page, })
def index(request, page=None): questions = Question.objects.newest() questions_on_page = paginate(questions, request, 10, page) return render(request, 'ask/index.html', { 'questions': questions_on_page, 'page': page, })
def tag(request, tag_name, page=None): questions = Question.objects.tag(tag_name=tag_name) questions_on_page = paginate(questions, request, 10, page) return render(request, 'ask/tag.html', { 'questions': questions_on_page, 'page': page, 'tag': tag_name, })
def question(request, question_id, page=None): ques = Question.objects.get(id=question_id) answers = ques.answer_set.all() answers_on_page = paginate(answers, request, 10, page) User = getAuthenticatedUser(request) if User != None: if request.POST: form = AnswerForm(request.POST) if form.is_valid(): answer = form.saveAnswer(User, question_id) page = answers.count() / 10 if (answers.count() % 10 != 0): page += 1 return redirect('/question/' + str(question_id) + '/' + str(page)) else: form = AnswerForm() else: form = AnswerForm() return render(request, 'ask/question.html', { 'answers': answers_on_page, 'question': ques, 'page': page, 'form' : form, })