diff mbox

[34/51] series: Enable sorting in the series list

Message ID 1441986924-26689-35-git-send-email-damien.lespiau@intel.com
State Superseded
Headers show

Commit Message

Damien Lespiau Sept. 11, 2015, 3:55 p.m. UTC
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 htdocs/js/patchwork.js | 9 +++++----
 patchwork/views/api.py | 5 ++++-
 2 files changed, 9 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/htdocs/js/patchwork.js b/htdocs/js/patchwork.js
index c1dfa6a..023de6a 100644
--- a/htdocs/js/patchwork.js
+++ b/htdocs/js/patchwork.js
@@ -25,8 +25,8 @@  var pw = (function() {
     var columnsMap = {
         'Series': 'name',
         'Patches': 'n_patches',
-        'Submitter': 'submitter_name',
-        'Reviewer': 'reviewer_name',
+        'Submitter': 'submitter__name',
+        'Reviewer': 'reviewer__name',
         'Submitted': 'submitted',
         'Updated': 'last_updated'
     };
@@ -67,7 +67,8 @@  var pw = (function() {
                 perPage: 'perpage',
                 records: 'results',
                 queryRecordCount: 'count',
-                totalRecordCount: 'count'
+                totalRecordCount: 'count',
+                sorts: 'ordering'
             },
             inputs: {
                 pageText: '',
@@ -79,7 +80,7 @@  var pw = (function() {
                 'name': series_writer,
                 'submitted': date_writer,
                 'last_updated': date_writer,
-                'reviewer_name': reviewer_writer
+                'reviewer__name': reviewer_writer
             }
         });
     }
diff --git a/patchwork/views/api.py b/patchwork/views/api.py
index 95124fa..c3756fa 100644
--- a/patchwork/views/api.py
+++ b/patchwork/views/api.py
@@ -18,7 +18,7 @@ 
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 from patchwork.models import Project, Series, SeriesRevision
-from rest_framework import viewsets, mixins, generics
+from rest_framework import viewsets, mixins, generics, filters
 from rest_framework.response import Response
 from rest_framework.generics import get_object_or_404
 from patchwork.serializers import ProjectSerializer, SeriesSerializer, \
@@ -44,6 +44,9 @@  class SeriesListViewSet(mixins.ListModelMixin,
     paginate_by = 20
     paginate_by_param = 'perpage'
     max_paginate_by = 100
+    filter_backends = (filters.OrderingFilter, )
+    ordering_fields = ('name', 'n_patches', 'submitter__name', 'reviewer__name',
+                        'submitted', 'last_updated')
 
     def get_queryset(self):
         filter_kwargs = { 'project__linkname': self.kwargs['project_pk'] }