-@decorators.render("question.html", 'questions', tabbed=False)
-def question(request, id, slug):
+def answer_redirect(request, answer):
+ pc = AnswerPaginatorContext()
+
+ sort = pc.sort(request)
+
+ if sort == _('oldest'):
+ filter = Q(added_at__lt=answer.added_at)
+ elif sort == _('newest'):
+ filter = Q(added_at__gt=answer.added_at)
+ elif sort == _('votes'):
+ filter = Q(score__gt=answer.score) | Q(score=answer.score, added_at__lt=answer.added_at)
+ else:
+ raise Http404()
+
+ count = answer.question.answers.filter(Q(marked=True) | filter).count()
+ pagesize = pc.pagesize(request)
+
+ page = count / pagesize
+
+ if count % pagesize:
+ page += 1
+
+ if page == 0:
+ page = 1
+
+ return HttpResponsePermanentRedirect("%s?%s=%s#%s" % (
+ answer.question.get_absolute_url(), _('page'), page, answer.id))
+
+@decorators.render("question.html", 'questions')
+def question(request, id, slug=None, answer=None):