summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-05-15 18:34:19 -0700
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-05-15 18:34:19 -0700
commitf44de3d77708d86c46428dc2b6e05aaa9c0597a0 (patch)
tree71512a33d5515134ff1160ce3fbc9d3e19d6e6d7
parent68883de9a3f294d3dfa7e59e6a8765c341d710a5 (diff)
parentf2c43c3fd41aa6fdc01f99c9075825e236e15159 (diff)
downloadaskbot-f44de3d77708d86c46428dc2b6e05aaa9c0597a0.tar.gz
askbot-f44de3d77708d86c46428dc2b6e05aaa9c0597a0.tar.bz2
askbot-f44de3d77708d86c46428dc2b6e05aaa9c0597a0.zip
Merge pull request #125 from fitoria/keyerrorissue
Fixes code that could produce KeyError in sorting methods
-rw-r--r--askbot/models/question.py14
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()