diff options
author | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2013-05-15 11:04:28 -0600 |
---|---|---|
committer | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2013-05-15 11:04:28 -0600 |
commit | f2c43c3fd41aa6fdc01f99c9075825e236e15159 (patch) | |
tree | 71512a33d5515134ff1160ce3fbc9d3e19d6e6d7 | |
parent | 68883de9a3f294d3dfa7e59e6a8765c341d710a5 (diff) | |
download | askbot-f2c43c3fd41aa6fdc01f99c9075825e236e15159.tar.gz askbot-f2c43c3fd41aa6fdc01f99c9075825e236e15159.tar.bz2 askbot-f2c43c3fd41aa6fdc01f99c9075825e236e15159.zip |
Fixes code that could produce KeyError in sorting methods
-rw-r--r-- | askbot/models/question.py | 14 |
1 files 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() |