summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--askbot/conf/forum_data_rules.py10
-rw-r--r--askbot/const/__init__.py8
-rw-r--r--askbot/doc/source/contributors.rst2
-rw-r--r--askbot/forms.py6
-rw-r--r--askbot/models/question.py31
-rw-r--r--askbot/views/readers.py4
6 files changed, 42 insertions, 19 deletions
diff --git a/askbot/conf/forum_data_rules.py b/askbot/conf/forum_data_rules.py
index f32f34bf..caa93563 100644
--- a/askbot/conf/forum_data_rules.py
+++ b/askbot/conf/forum_data_rules.py
@@ -225,6 +225,16 @@ settings.register(
)
settings.register(
+ livesettings.StringValue(
+ FORUM_DATA_RULES,
+ 'DEFAULT_ANSWER_SORT_METHOD',
+ default=const.DEFAULT_ANSWER_SORT_METHOD,
+ choices=const.ANSWER_SORT_METHODS,
+ description=_('How to sort answers by default')
+ )
+)
+
+settings.register(
livesettings.BooleanValue(
FORUM_DATA_RULES,
'TAGS_ARE_REQUIRED',
diff --git a/askbot/const/__init__.py b/askbot/const/__init__.py
index 649e1dd1..ff1d0883 100644
--- a/askbot/const/__init__.py
+++ b/askbot/const/__init__.py
@@ -110,9 +110,13 @@ REPLY_WITH_COMMENT_TEMPLATE = _(
)
REPLY_SEPARATOR_REGEX = re.compile(r'==== .* -=-==', re.MULTILINE|re.DOTALL)
-ANSWER_SORT_METHODS = (#no translations needed here
- 'latest', 'oldest', 'votes'
+ANSWER_SORT_METHODS = (
+ ('latest' , _('latest first')),
+ ('oldest', _('oldest first')),
+ ('votes', _('most voted first')),
)
+DEFAULT_ANSWER_SORT_METHOD = 'votes'
+
#todo: add assertion here that all sort methods are unique
#because they are keys to the hash used in implementations
#of Q.run_advanced_search
diff --git a/askbot/doc/source/contributors.rst b/askbot/doc/source/contributors.rst
index 04a93e40..5e97b608 100644
--- a/askbot/doc/source/contributors.rst
+++ b/askbot/doc/source/contributors.rst
@@ -48,7 +48,7 @@ Programming, bug fixes and documentation
* `Zafer Cakmak <https://github.com/xaph>`_
* `Kevin Porterfield <http://www.shotgunsoftware.com>_`
* `Robert Martin <https://github.com/bobbydavid>_`
-* `pcompassion https://github.com/pcompassion`_
+* `Director <http://codeflow.co.kr>`_
Translations
------------
diff --git a/askbot/forms.py b/askbot/forms.py
index 9b332518..0c4e15c5 100644
--- a/askbot/forms.py
+++ b/askbot/forms.py
@@ -557,14 +557,16 @@ class ShowQuestionForm(forms.Form):
in_data = self.get_pruned_data()
out_data = dict()
+ default_answer_sort = askbot_settings.DEFAULT_ANSWER_SORT_METHOD
if ('answer' in in_data) ^ ('comment' in in_data):
out_data['show_page'] = None
- out_data['answer_sort_method'] = 'votes'
+ out_data['answer_sort_method'] = default_answer_sort
out_data['show_comment'] = in_data.get('comment', None)
out_data['show_answer'] = in_data.get('answer', None)
else:
out_data['show_page'] = in_data.get('page', 1)
- out_data['answer_sort_method'] = in_data.get('sort', 'votes')
+ answer_sort_method = in_data.get('sort', default_answer_sort)
+ out_data['answer_sort_method'] = answer_sort_method
out_data['show_comment'] = None
out_data['show_answer'] = None
self.cleaned_data = out_data
diff --git a/askbot/models/question.py b/askbot/models/question.py
index b8652c6b..fe68870a 100644
--- a/askbot/models/question.py
+++ b/askbot/models/question.py
@@ -921,7 +921,8 @@ class Thread(models.Model):
changes in the post data - on votes, adding,
deleting, editing content"""
#we can call delete_many() here if using Django > 1.2
- for sort_method in const.ANSWER_SORT_METHODS:
+ sort_methods = map(lambda v: v[0], const.ANSWER_SORT_METHODS)
+ for sort_method in sort_methods:
cache.cache.delete(self.get_post_data_cache_key(sort_method))
def invalidate_cached_data(self, lazy=False):
@@ -931,9 +932,11 @@ class Thread(models.Model):
else:
self.update_summary_html()
- def get_cached_post_data(self, user = None, sort_method = 'votes'):
+ def get_cached_post_data(self, user = None, sort_method = None):
"""returns cached post data, as calculated by
the method get_post_data()"""
+ sort_method = sort_method or askbot_settings.DEFAULT_ANSWER_SORT_METHOD
+
if askbot_settings.GROUPS_ENABLED:
#temporary plug: bypass cache where groups are enabled
return self.get_post_data(sort_method=sort_method, user=user)
@@ -944,7 +947,7 @@ class Thread(models.Model):
cache.cache.set(key, post_data, const.LONG_TIME)
return post_data
- def get_post_data(self, sort_method='votes', user=None):
+ def get_post_data(self, sort_method=None, user=None):
"""returns question, answers as list and a list of post ids
for the given thread, and the list of published post ids
(four values)
@@ -952,6 +955,8 @@ class Thread(models.Model):
all (both posts and the comments sorted in the correct
order)
"""
+ sort_method = sort_method or askbot_settings.DEFAULT_ANSWER_SORT_METHOD
+
thread_posts = self.posts.all()
if askbot_settings.GROUPS_ENABLED:
if user is None or user.is_anonymous():
@@ -967,12 +972,18 @@ class Thread(models.Model):
'oldest':'added_at',
'votes':'-points'
}
- if sort_method in order_by_method:
- order_by = order_by_method[sort_method]
+
+ default_answer_sort_method = askbot_settings.DEFAULT_ANSWER_SORT_METHOD
+ default_order_by_method = order_by_method[default_answer_sort_method]
+ order_by = order_by_method.get(sort_method, default_order_by_method)
+ #we add secondary sort method for the answers to make
+ #discussion more coherent
+ if order_by != default_order_by_method:
+ order_by = (order_by, default_order_by_method)
else:
- order_by = order_by_method['latest']
+ order_by = (order_by,)
- thread_posts = thread_posts.order_by(order_by)
+ 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()
@@ -1032,11 +1043,7 @@ class Thread(models.Model):
).filter(
deleted=False
).order_by(
- {
- 'latest':'-added_at',
- 'oldest':'added_at',
- 'votes':'-points'
- }[sort_method]
+ *order_by
).values_list('id', flat=True)
published_answer_ids = reversed(published_answer_ids)
diff --git a/askbot/views/readers.py b/askbot/views/readers.py
index 99f5b024..8bf2cea9 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -503,8 +503,8 @@ def question(request, id):#refactor - long subroutine. display question body, an
#load answers and post id's->athor_id mapping
#posts are pre-stuffed with the correctly ordered comments
updated_question_post, answers, post_to_author, published_answer_ids = thread.get_cached_post_data(
- sort_method = answer_sort_method,
- user = request.user
+ sort_method=answer_sort_method,
+ user=request.user
)
question_post.set_cached_comments(
updated_question_post.get_cached_comments()