From: hernani Date: Thu, 8 Jul 2010 23:22:54 +0000 (+0000) Subject: Improves the answer position guessing. X-Git-Tag: live~627 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/5c7287b435f2e68257bce3b76ee435d9b07f87f9?ds=sidebyside;hp=0d5a900153f251326bbe15d87e8b1ef054f3d344 Improves the answer position guessing. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@507 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/utils/pagination.py b/forum/utils/pagination.py index e3cfc29..641c549 100644 --- a/forum/utils/pagination.py +++ b/forum/utils/pagination.py @@ -15,7 +15,10 @@ class SimpleSort(object): self.order_by = order_by def apply(self, objects): - return objects.order_by(self.order_by) + if isinstance(self.order_by, (list, tuple)): + return objects.order_by(*self.order_by) + else: + return objects.order_by(self.order_by) class DummySort(object): def __init__(self, label, description=''): diff --git a/forum/views/readers.py b/forum/views/readers.py index a60db45..4bdb58b 100644 --- a/forum/views/readers.py +++ b/forum/views/readers.py @@ -40,19 +40,12 @@ class QuestionListPaginatorContext(pagination.PaginatorContext): (_('mostvoted'), pagination.SimpleSort(_('most voted'), '-score', _("most voted questions"))), ), pagesizes=(15, 30, 50), default_pagesize=default_pagesize, prefix=prefix) -class AnswerSort(pagination.SimpleSort): - def apply(self, objects): - if self.label == _('votes'): - return objects.order_by('-marked', self.order_by, 'added_at') - else: - return objects.order_by('-marked', self.order_by) - class AnswerPaginatorContext(pagination.PaginatorContext): def __init__(self, id='ANSWER_LIST', prefix='', default_pagesize=10): super (AnswerPaginatorContext, self).__init__(id, sort_methods=( - (_('oldest'), AnswerSort(_('oldest answers'), 'added_at', _("oldest answers will be shown first"))), - (_('newest'), AnswerSort(_('newest answers'), '-added_at', _("newest answers will be shown first"))), - (_('votes'), AnswerSort(_('popular answers'), '-score', _("most voted answers will be shown first"))), + (_('oldest'), pagination.SimpleSort(_('oldest answers'), ('-marked', 'added_at'), _("oldest answers will be shown first"))), + (_('newest'), pagination.SimpleSort(_('newest answers'), ('-marked', '-added_at'), _("newest answers will be shown first"))), + (_('votes'), pagination.SimpleSort(_('popular answers'), ('-marked', '-score', 'added_at'), _("most voted answers will be shown first"))), ), default_sort=_('votes'), sticky_sort = True, pagesizes=(5, 10, 20), default_pagesize=default_pagesize, prefix=prefix) class TagPaginatorContext(pagination.PaginatorContext):