diff mbox

[v2,2/3] REST: Integrate searching

Message ID 20170102212347.18089-2-stephen@that.guru
State Accepted
Headers show

Commit Message

Stephen Finucane Jan. 2, 2017, 9:23 p.m. UTC
Search by way of the 'q' parameter on many endpoints.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Cc: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Cc: Russell Currey <ruscur@russell.cc>
---
 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 | 2 ++
 7 files changed, 9 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py
index 6374ce9..0b6b546 100644
--- a/patchwork/api/cover.py
+++ b/patchwork/api/cover.py
@@ -68,6 +68,7 @@  class CoverLetterList(ListAPIView):
 
     serializer_class = CoverLetterListSerializer
     filter_class = CoverLetterFilter
+    search_fields = ('name',)
 
     def get_queryset(self):
         qs = CoverLetter.objects.all().prefetch_related('series')\
diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
index d12464f..fc5a0ee 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -119,6 +119,7 @@  class PatchList(ListAPIView):
     permission_classes = (PatchworkPermission,)
     serializer_class = PatchListSerializer
     filter_class = PatchFilter
+    search_fields = ('name',)
 
     def get_queryset(self):
         return Patch.objects.all().with_tag_counts()\
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 3cc2c32..8901ab4 100644
--- a/patchwork/api/project.py
+++ b/patchwork/api/project.py
@@ -74,7 +74,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 edde9a9..996094b 100644
--- a/patchwork/api/series.py
+++ b/patchwork/api/series.py
@@ -56,6 +56,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 35b85c7..82fd9c2 100644
--- a/patchwork/settings/base.py
+++ b/patchwork/settings/base.py
@@ -146,7 +146,9 @@  REST_FRAMEWORK = {
     'DEFAULT_PAGINATION_CLASS': 'patchwork.api.base.LinkHeaderPagination',
     'DEFAULT_FILTER_BACKENDS': (
         'django_filters.rest_framework.DjangoFilterBackend',
+        'rest_framework.filters.SearchFilter',
     ),
+    'SEARCH_PARAM': 'q',
 }
 
 #