[PATCH 38/51] api: Extract a SeriesList mixin

Damien Lespiau damien.lespiau at intel.com
Sat Sep 12 01:55:11 AEST 2015


I'd like another API entry point to present a list of series. Let's
gather the common properties we can reuse into a mixin class.

Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
 patchwork/views/api.py | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/patchwork/views/api.py b/patchwork/views/api.py
index a0904b2..8ab17b3 100644
--- a/patchwork/views/api.py
+++ b/patchwork/views/api.py
@@ -52,6 +52,16 @@ class UserViewSet(viewsets.ViewSet):
         serializer = UserSerializer(self)
         return Response(serializer.data)
 
+class SeriesListMixin:
+    queryset = Series.objects.all()
+    serializer_class = SeriesSerializer
+    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')
+
 class ProjectViewSet(viewsets.ViewSet):
     permission_classes = (MaintainerPermission, )
     model = Project
@@ -67,16 +77,9 @@ class ProjectViewSet(viewsets.ViewSet):
         return Response(serializer.data)
 
 class SeriesListViewSet(mixins.ListModelMixin,
+                        SeriesListMixin,
                         viewsets.GenericViewSet):
     permission_classes = (MaintainerPermission, )
-    queryset = Series.objects.all()
-    serializer_class = SeriesSerializer
-    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'] }
-- 
2.1.0



More information about the Patchwork mailing list