diff mbox

[39/51] api: Add a way to retrieve the list of pending reviews

Message ID 1441986924-26689-40-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>
---
 patchwork/urls.py      |  4 ++++
 patchwork/views/api.py | 12 ++++++++++++
 2 files changed, 16 insertions(+)
diff mbox

Patch

diff --git a/patchwork/urls.py b/patchwork/urls.py
index 7052941..36fc5f9 100644
--- a/patchwork/urls.py
+++ b/patchwork/urls.py
@@ -30,6 +30,9 @@  import patchwork.views.api as api
 # /self
 users_router = routers.SimpleRouter()
 users_router.register('self', api.UserViewSet)
+# /self/reviews
+self_reviews_router = routers.SimpleRouter()
+self_reviews_router.register('self/reviews', api.SeriesReviewsViewSet)
 # /projects/$project/
 project_router = routers.SimpleRouter()
 project_router.register('projects', api.ProjectViewSet)
@@ -52,6 +55,7 @@  urlpatterns = patterns('',
 
     # API
     (r'^api/1.0/', include(users_router.urls)),
+    (r'^api/1.0/', include(self_reviews_router.urls)),
     (r'^api/1.0/', include(project_router.urls)),
     (r'^api/1.0/', include(series_list_router.urls)),
     (r'^api/1.0/', include(series_router.urls)),
diff --git a/patchwork/views/api.py b/patchwork/views/api.py
index 8ab17b3..4b843b9 100644
--- a/patchwork/views/api.py
+++ b/patchwork/views/api.py
@@ -62,6 +62,18 @@  class SeriesListMixin:
     ordering_fields = ('name', 'n_patches', 'submitter__name', 'reviewer__name',
                         'submitted', 'last_updated')
 
+class SeriesReviewsViewSet(mixins.ListModelMixin,
+                           SeriesListMixin,
+                           viewsets.GenericViewSet):
+    permission_classes = (UserPermission, )
+
+    def get_queryset(self):
+        filter_kwargs = { 'reviewer': self.request.user }
+
+        # Ensure queryset is re-evaluated on each request.
+        queryset = self.queryset.filter(**filter_kwargs)
+        return queryset
+
 class ProjectViewSet(viewsets.ViewSet):
     permission_classes = (MaintainerPermission, )
     model = Project