X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/9694fb0873b055992c5d2d00ff12f946b2f26c08..a0273ff358d8725b4f137dfa95754c3c43379ecb:/forum/views/readers.py?ds=sidebyside diff --git a/forum/views/readers.py b/forum/views/readers.py index 8dad780..669eaf3 100644 --- a/forum/views/readers.py +++ b/forum/views/readers.py @@ -92,7 +92,9 @@ def unanswered(request): @decorators.render('questions.html', 'questions', _('questions'), weight=0) def questions(request): - return question_list(request, Question.objects.all(), _('questions')) + return question_list(request, + Question.objects.all(), + _('questions')) @decorators.render('questions.html') def tag(request, tag): @@ -119,12 +121,18 @@ def tag(request, tag): } # The context returned by the question_list function, contains info about the questions - question_context = dict(question_list(request, + question_context = question_list(request, questions, mark_safe(_(u'questions tagged %(tag)s') % {'tag': tag}), None, mark_safe(_(u'Questions Tagged With %(tag)s') % {'tag': tag}), - False)) + False) + + # If the return data type is not a dict just return it + if not isinstance(question_context, dict): + return question_context + + question_context = dict(question_context) # Create the combined context context = dict(question_context.items() + tag_context.items()) @@ -165,8 +173,13 @@ def question_list(request, initial, allowIgnoreTags=True, feed_url=None, paginator_context=None, + show_summary=None, feed_sort=('-added_at',), - feed_req_params_exclude=(_('page'), _('pagesize'), _('sort'))): + feed_req_params_exclude=(_('page'), _('pagesize'), _('sort')), + extra_context={}): + + if show_summary is None: + show_summary = bool(settings.SHOW_SUMMARY_ON_QUESTIONS_LIST) questions = initial.filter_state(deleted=False) @@ -205,7 +218,9 @@ def question_list(request, initial, 'page_title' : page_title, 'tab' : 'questions', 'feed_url': feed_url, + 'show_summary' : show_summary, } + context.update(extra_context) return pagination.paginated(request, ('questions', paginator_context or QuestionListPaginatorContext()), context) @@ -316,8 +331,8 @@ def answer_redirect(request, answer): if page == 0: page = 1 - return HttpResponsePermanentRedirect("%s?%s=%s#%s" % ( - answer.question.get_absolute_url(), _('page'), page, answer.id)) + return HttpResponseRedirect("%s?%s=%s&focusedAnswerId=%s#%s" % ( + answer.question.get_absolute_url(), _('page'), page, answer.id, answer.id)) @decorators.render("question.html", 'questions') def question(request, id, slug='', answer=None): @@ -367,6 +382,10 @@ def question(request, id, slug='', answer=None): subscription = False else: subscription = False + try: + focused_answer_id = int(request.GET.get("focusedAnswerId", None)) + except TypeError, ValueError: + focused_answer_id = None return pagination.paginated(request, ('answers', AnswerPaginatorContext()), { "question" : question, @@ -375,6 +394,7 @@ def question(request, id, slug='', answer=None): "similar_questions" : question.get_related_questions(), "subscription": subscription, "embed_youtube_videos" : settings.EMBED_YOUTUBE_VIDEOS, + "focused_answer_id" : focused_answer_id })