From patchwork Fri Sep 11 15:54:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Lespiau X-Patchwork-Id: 516865 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6EFFE140180 for ; Sat, 12 Sep 2015 01:58:59 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 558801A2BBC for ; Sat, 12 Sep 2015 01:58:59 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lists.ozlabs.org (Postfix) with ESMTP id 6FFD51A2BBD for ; Sat, 12 Sep 2015 01:55:46 +1000 (AEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 11 Sep 2015 08:55:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,511,1437462000"; d="scan'208";a="559867046" Received: from jeffzhua-mobl.amr.corp.intel.com (HELO strange.amr.corp.intel.com) ([10.254.88.85]) by FMSMGA003.fm.intel.com with ESMTP; 11 Sep 2015 08:55:45 -0700 From: Damien Lespiau To: patchwork@lists.ozlabs.org Subject: [PATCH 21/51] api: Expose Revisions Date: Fri, 11 Sep 2015 16:54:54 +0100 Message-Id: <1441986924-26689-22-git-send-email-damien.lespiau@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1441986924-26689-1-git-send-email-damien.lespiau@intel.com> References: <1441986924-26689-1-git-send-email-damien.lespiau@intel.com> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Signed-off-by: Damien Lespiau --- patchwork/serializers.py | 22 +++++++++++++++++++++- patchwork/urls.py | 9 +++++++++ patchwork/views/api.py | 19 +++++++++++++++++-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/patchwork/serializers.py b/patchwork/serializers.py index 468daa7..05c9f15 100644 --- a/patchwork/serializers.py +++ b/patchwork/serializers.py @@ -17,7 +17,7 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from patchwork.models import Project, Series +from patchwork.models import Project, Series, SeriesRevision, Patch from rest_framework import serializers class ProjectSerializer(serializers.HyperlinkedModelSerializer): @@ -39,3 +39,23 @@ class SeriesSerializer(serializers.ModelSerializer): 'reviewer__name') read_only_fields = ('n_patches', 'submitter', 'submitted', 'last_updated', 'version') + +class PatchSerializer(serializers.ModelSerializer): + submitter__name = serializers.CharField(source='submitter.name', + read_only=True) + state__name = serializers.CharField(source='state.name', read_only=True) + class Meta: + model = Patch + fields = ('name', 'msgid', 'date', 'submitter', 'submitter__name', + 'state', 'state__name', 'archived', 'content') + read_only_fields = ('name', 'msgid', 'date', 'submitter', 'archived', + 'content') + + +class RevisionSerializer(serializers.HyperlinkedModelSerializer): + patches = PatchSerializer(many=True, read_only=True) + + class Meta: + model = SeriesRevision + fields = ('version', 'cover_letter', 'patches') + read_only_fields = ('version', 'cover_letter') diff --git a/patchwork/urls.py b/patchwork/urls.py index 041ba1c..67c6c6b 100644 --- a/patchwork/urls.py +++ b/patchwork/urls.py @@ -33,6 +33,13 @@ project_router.register('projects', api.ProjectViewSet) series_list_router = routers.NestedSimpleRouter(project_router, 'projects', lookup='project') series_list_router.register(r'series', api.SeriesListViewSet) +# /series/$id/ +series_router = routers.SimpleRouter() +series_router.register(r'series', api.SeriesViewSet) +# /series/$id/revisions/$rev +revisions_router = routers.NestedSimpleRouter(series_router, 'series', + lookup='series') +revisions_router.register(r'revisions', api.RevisionViewSet) admin.autodiscover() @@ -42,6 +49,8 @@ urlpatterns = patterns('', # API (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)), + (r'^api/1.0/', include(revisions_router.urls)), # Example: (r'^$', 'patchwork.views.projects'), diff --git a/patchwork/views/api.py b/patchwork/views/api.py index fa8ebc1..95124fa 100644 --- a/patchwork/views/api.py +++ b/patchwork/views/api.py @@ -17,11 +17,12 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from patchwork.models import Project, Series +from patchwork.models import Project, Series, SeriesRevision from rest_framework import viewsets, mixins, generics from rest_framework.response import Response from rest_framework.generics import get_object_or_404 -from patchwork.serializers import ProjectSerializer, SeriesSerializer +from patchwork.serializers import ProjectSerializer, SeriesSerializer, \ + RevisionSerializer class ProjectViewSet(viewsets.ViewSet): model = Project @@ -50,3 +51,17 @@ class SeriesListViewSet(mixins.ListModelMixin, # Ensure queryset is re-evaluated on each request. queryset = self.queryset.filter(**filter_kwargs) return queryset + +class SeriesViewSet(mixins.RetrieveModelMixin, + mixins.UpdateModelMixin, + viewsets.GenericViewSet): + queryset = Series.objects.all() + serializer_class = SeriesSerializer + +class RevisionViewSet(viewsets.ViewSet): + model = SeriesRevision + + def retrieve(self, request, series_pk=None, pk=None): + rev = get_object_or_404(SeriesRevision, series=series_pk, version=pk) + serializer = RevisionSerializer(rev) + return Response(serializer.data)