]> git.openstreetmap.org Git - osqa.git/commitdiff
Improves the answer position guessing.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 8 Jul 2010 23:22:54 +0000 (23:22 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 8 Jul 2010 23:22:54 +0000 (23:22 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@507 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/utils/pagination.py
forum/views/readers.py

index e3cfc291e2c40dc949746f747b5172e2ddef3c64..641c549747b9f1910493ed492f324c0f6ba71bb7 100644 (file)
@@ -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=''):
index a60db45b2ea6735326b011618df9683dc3f4219c..4bdb58bc9a438e3d0722a4446f8011c45ec76bba 100644 (file)
@@ -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):