Skip to content
This repository was archived by the owner on Sep 3, 2020. It is now read-only.

Commit 0f406cd

Browse files
author
Arjun
committed
beta 5.6
Bug Fixes
1 parent e944973 commit 0f406cd

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

qa/views.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,34 @@ def comment(request, answer_id):
157157

158158
pub_date = datetime.datetime.now()
159159
a = Answer.objects.get(pk=answer_id)
160+
q_id = a.question_id
160161
c = Comment()
161162
c.answer = a
162163
c.comment_text = comment_text
163164
c.pub_date = pub_date
164165
c.user_data = user
165166
c.save()
166-
return HttpResponseRedirect('/')
167+
168+
try:
169+
question = Question.objects.get(pk=q_id)
170+
question.views += 1
171+
question.save()
172+
answer_list = question.answer_set.order_by('-votes')
173+
174+
paginator = Paginator(answer_list, 10)
175+
page = request.GET.get('page')
176+
try:
177+
answers = paginator.page(page)
178+
except PageNotAnInteger:
179+
# If page is not an integer, deliver first page.
180+
answers = paginator.page(1)
181+
except EmptyPage:
182+
# If page is out of range (e.g. 9999), deliver last page of results.
183+
answers = paginator.page(paginator.num_pages)
184+
185+
except Question.DoesNotExist:
186+
raise Http404("Question does not exist")
187+
return render(request, 'qa/detail.html', {'answers': answers, 'question': question}, )
167188

168189
template = loader.get_template('qa/comment.html')
169190
context = RequestContext(request, {'answer_id': answer_id})
@@ -194,7 +215,7 @@ def detail(request, question_id):
194215
def answer(request, question_id):
195216
if request.user.is_anonymous():
196217
return HttpResponseRedirect("/login/")
197-
218+
198219
try:
199220
question = Question.objects.get(pk=question_id)
200221
except Question.DoesNotExist:

0 commit comments

Comments
 (0)