[RFC 2/2] REST: Integrate searching

Stephen Finucane stephen at that.guru
Thu Nov 17 12:47:23 AEDT 2016


Search by way of the 'q' parameter on many endpoints

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/api/cover.py     | 1 +
 patchwork/api/patch.py     | 1 +
 patchwork/api/person.py    | 2 +-
 patchwork/api/project.py   | 3 ++-
 patchwork/api/series.py    | 1 +
 patchwork/api/user.py      | 2 +-
 patchwork/settings/base.py | 4 +++-
 7 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py
index 189e2ed..4c5a18e 100644
--- a/patchwork/api/cover.py
+++ b/patchwork/api/cover.py
@@ -69,6 +69,7 @@ class CoverLetterList(ListAPIView):
         'series').select_related('submitter').defer('content', 'headers')
     serializer_class = CoverLetterListSerializer
     filter_class = CoverLetterFilter
+    search_fields = ('name',)
 
 
 class CoverLetterDetail(RetrieveAPIView):
diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
index 149b3ae..cdcf6cc 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -120,6 +120,7 @@ class PatchList(ListAPIView):
     permission_classes = (PatchworkPermission,)
     serializer_class = PatchListSerializer
     filter_class = PatchFilter
+    search_fields = ('name',)
 
 
 class PatchDetail(RetrieveUpdateAPIView):
diff --git a/patchwork/api/person.py b/patchwork/api/person.py
index 2c1ca15..10cf781 100644
--- a/patchwork/api/person.py
+++ b/patchwork/api/person.py
@@ -46,7 +46,7 @@ class PersonMixin(object):
 class PersonList(PersonMixin, ListAPIView):
     """List users."""
 
-    pass
+    search_fields = ('name', 'email')
 
 
 class PersonDetail(PersonMixin, RetrieveAPIView):
diff --git a/patchwork/api/project.py b/patchwork/api/project.py
index 388081a..2e43ab5 100644
--- a/patchwork/api/project.py
+++ b/patchwork/api/project.py
@@ -70,7 +70,8 @@ class ProjectMixin(object):
 class ProjectList(ProjectMixin, ListAPIView):
     """List projects."""
 
-    pass
+    search_fields = ('link_name', 'list_id', 'list_email', 'web_url',
+                     'scm_url', 'webscm_url')
 
 
 class ProjectDetail(ProjectMixin, RetrieveUpdateAPIView):
diff --git a/patchwork/api/series.py b/patchwork/api/series.py
index 9771bf4..937f454 100644
--- a/patchwork/api/series.py
+++ b/patchwork/api/series.py
@@ -53,6 +53,7 @@ class SeriesList(SeriesMixin, ListAPIView):
     """List series."""
 
     filter_class = SeriesFilter
+    search_fields = ('name',)
 
 
 class SeriesDetail(SeriesMixin, RetrieveAPIView):
diff --git a/patchwork/api/user.py b/patchwork/api/user.py
index 2153cc9..2c9f71b 100644
--- a/patchwork/api/user.py
+++ b/patchwork/api/user.py
@@ -56,7 +56,7 @@ class UserMixin(object):
 class UserList(UserMixin, ListAPIView):
     """List users."""
 
-    pass
+    search_fields = ('username', 'first_name', 'last_name', 'email')
 
 
 class UserDetail(UserMixin, RetrieveUpdateAPIView):
diff --git a/patchwork/settings/base.py b/patchwork/settings/base.py
index dd2d3d0..f0d9867 100644
--- a/patchwork/settings/base.py
+++ b/patchwork/settings/base.py
@@ -147,7 +147,9 @@ REST_FRAMEWORK = {
     'DEFAULT_PAGINATION_CLASS': 'patchwork.api.LinkHeaderPagination',
     'DEFAULT_FILTER_BACKENDS': (
         'django_filters.rest_framework.DjangoFilterBackend',
-    )
+        'rest_framework.filters.SearchFilter',
+    ),
+    'SEARCH_PARAM': 'q',
 }
 
 #
-- 
2.7.4



More information about the Patchwork mailing list