[PATCH v2 3/3] REST: Integrate ordering

Stephen Finucane stephen at that.guru
Tue Jan 3 08:23:47 AEDT 2017


Order by way of the 'order' parameter on many endpoints.

Signed-off-by: Stephen Finucane <stephen at that.guru>
Cc: Andrew Donnellan <andrew.donnellan at au1.ibm.com>
Cc: Russell Currey <ruscur at russell.cc>
---
 patchwork/api/cover.py     | 1 +
 patchwork/api/patch.py     | 2 ++
 patchwork/api/person.py    | 1 +
 patchwork/api/project.py   | 1 +
 patchwork/api/series.py    | 1 +
 patchwork/api/user.py      | 1 +
 patchwork/settings/base.py | 2 ++
 7 files changed, 9 insertions(+)

diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py
index 0b6b546..8b8d47b 100644
--- a/patchwork/api/cover.py
+++ b/patchwork/api/cover.py
@@ -69,6 +69,7 @@ class CoverLetterList(ListAPIView):
     serializer_class = CoverLetterListSerializer
     filter_class = CoverLetterFilter
     search_fields = ('name',)
+    ordering_fields = ('id', 'name', 'date', 'submitter')
 
     def get_queryset(self):
         qs = CoverLetter.objects.all().prefetch_related('series')\
diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
index fc5a0ee..e8fb0ef 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -120,6 +120,8 @@ class PatchList(ListAPIView):
     serializer_class = PatchListSerializer
     filter_class = PatchFilter
     search_fields = ('name',)
+    ordering_fields = ('id', 'name', 'project', 'date', 'state', 'archived',
+                       'submitter', 'check')
 
     def get_queryset(self):
         return Patch.objects.all().with_tag_counts()\
diff --git a/patchwork/api/person.py b/patchwork/api/person.py
index 10cf781..7947f82 100644
--- a/patchwork/api/person.py
+++ b/patchwork/api/person.py
@@ -47,6 +47,7 @@ class PersonList(PersonMixin, ListAPIView):
     """List users."""
 
     search_fields = ('name', 'email')
+    ordering_fields = ('id', 'name', 'email')
 
 
 class PersonDetail(PersonMixin, RetrieveAPIView):
diff --git a/patchwork/api/project.py b/patchwork/api/project.py
index 8901ab4..ce3ed58 100644
--- a/patchwork/api/project.py
+++ b/patchwork/api/project.py
@@ -76,6 +76,7 @@ class ProjectList(ProjectMixin, ListAPIView):
 
     search_fields = ('link_name', 'list_id', 'list_email', 'web_url',
                      'scm_url', 'webscm_url')
+    ordering_fields = ('id', 'name', 'link_name', 'list_id')
 
 
 class ProjectDetail(ProjectMixin, RetrieveUpdateAPIView):
diff --git a/patchwork/api/series.py b/patchwork/api/series.py
index 996094b..6fe0e21 100644
--- a/patchwork/api/series.py
+++ b/patchwork/api/series.py
@@ -57,6 +57,7 @@ class SeriesList(SeriesMixin, ListAPIView):
 
     filter_class = SeriesFilter
     search_fields = ('name',)
+    ordering_fields = ('id', 'name', 'date', 'submitter', 'received_all')
 
 
 class SeriesDetail(SeriesMixin, RetrieveAPIView):
diff --git a/patchwork/api/user.py b/patchwork/api/user.py
index 2c9f71b..32fe836 100644
--- a/patchwork/api/user.py
+++ b/patchwork/api/user.py
@@ -57,6 +57,7 @@ class UserList(UserMixin, ListAPIView):
     """List users."""
 
     search_fields = ('username', 'first_name', 'last_name', 'email')
+    ordering_fields = ('id', 'username', 'email')
 
 
 class UserDetail(UserMixin, RetrieveUpdateAPIView):
diff --git a/patchwork/settings/base.py b/patchwork/settings/base.py
index 82fd9c2..6737350 100644
--- a/patchwork/settings/base.py
+++ b/patchwork/settings/base.py
@@ -147,8 +147,10 @@ REST_FRAMEWORK = {
     'DEFAULT_FILTER_BACKENDS': (
         'django_filters.rest_framework.DjangoFilterBackend',
         'rest_framework.filters.SearchFilter',
+        'rest_framework.filters.OrderingFilter',
     ),
     'SEARCH_PARAM': 'q',
+    'ORDERING_PARAM': 'order',
 }
 
 #
-- 
2.9.3



More information about the Patchwork mailing list