From f2c43c3fd41aa6fdc01f99c9075825e236e15159 Mon Sep 17 00:00:00 2001 From: Adolfo Fitoria Date: Wed, 15 May 2013 11:04:28 -0600 Subject: Fixes code that could produce KeyError in sorting methods --- askbot/models/question.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/askbot/models/question.py b/askbot/models/question.py index c772804a..8a00a3c3 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -344,7 +344,7 @@ class ThreadManager(BaseQuerySetManager): #a special case: "personalized" main page only == #if followed is the only available scope - #if total number (regardless of users selections) + #if total number (regardless of users selections) #followed questions is < than a pagefull - we should mix in a list of #random questions if askbot_settings.ALL_SCOPE_ENABLED == askbot_settings.UNANSWERED_SCOPE_ENABLED == False: @@ -890,13 +890,17 @@ class Thread(models.Model): thread_posts = thread_posts.filter(groups__in=groups) thread_posts = thread_posts.distinct()#important for >1 group - thread_posts = thread_posts.order_by( - { + order_by_method = { 'latest':'-added_at', 'oldest':'added_at', 'votes':'-points' - }[sort_method] - ) + } + if sort_method in order_by_method: + order_by = order_by_method[sort_method] + else: + order_by = order_by_method['latest'] + + thread_posts = thread_posts.order_by(order_by) #1) collect question, answer and comment posts and list of post id's answers = list() post_map = dict() -- cgit v1.2.3-1-g7c22