[RFC 11/11] REST: Add States to the API
Andy Doan
andy.doan at linaro.org
Sat Apr 16 04:24:07 AEST 2016
This exports patch States via the REST API.
Security Constraints:
* Anyone (logged in or not) can read all objects.
* No one can create/update/delete
Signed-off-by: Andy Doan <andy.doan at linaro.org>
---
patchwork/views/rest_api.py | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/patchwork/views/rest_api.py b/patchwork/views/rest_api.py
index e2ec616..15a75c7 100644
--- a/patchwork/views/rest_api.py
+++ b/patchwork/views/rest_api.py
@@ -19,7 +19,7 @@
from django.conf.urls import url, include
-from patchwork.models import Check, Patch, Person, Project
+from patchwork.models import Check, Patch, Person, Project, State
from patchwork.views.patch import mbox
from rest_framework import permissions
@@ -29,7 +29,8 @@ from rest_framework.response import Response
from rest_framework.routers import DefaultRouter
from rest_framework.serializers import (
CurrentUserDefault, HiddenField, ModelSerializer, PrimaryKeyRelatedField)
-from rest_framework.viewsets import GenericViewSet, ModelViewSet
+from rest_framework.viewsets import (
+ GenericViewSet, ModelViewSet, ReadOnlyModelViewSet)
from rest_framework_nested.routers import NestedSimpleRouter
@@ -200,10 +201,18 @@ class MboxViewSet(GenericViewSet):
return mbox(request, patch_pk)
+class StateViewSet(ReadOnlyModelViewSet):
+ serializer_class = create_model_serializer(State)
+
+ def get_queryset(self):
+ return self.serializer_class.Meta.model.objects.all()
+
+
router = DefaultRouter()
router.register('patches', PatchViewSet, 'patch')
router.register('people', PeopleViewSet, 'person')
router.register('projects', ProjectViewSet, 'project')
+router.register('states', StateViewSet, 'state')
patches_router = NestedSimpleRouter(router, r'patches', lookup='patch')
patches_router.register(r'checks', ChecksViewSet, base_name='patch-checks')
--
2.7.4
More information about the Patchwork
mailing list