From patchwork Fri Sep 11 15:54:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Lespiau X-Patchwork-Id: 516862 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BA2A1140180 for ; Sat, 12 Sep 2015 01:58:30 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 9925E1A2BDF for ; Sat, 12 Sep 2015 01:58:30 +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 E029E1A2ADA for ; Sat, 12 Sep 2015 01:55:43 +1000 (AEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 11 Sep 2015 08:55:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,511,1437462000"; d="scan'208";a="559867028" 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:42 -0700 From: Damien Lespiau To: patchwork@lists.ozlabs.org Subject: [PATCH 18/51] api: Expose projects Date: Fri, 11 Sep 2015 16:54:51 +0100 Message-Id: <1441986924-26689-19-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" We'll expose Series and Patches as sub-urls of projects. So they are a good object to start with. Signed-off-by: Damien Lespiau --- apps/patchwork/serializers.py | 27 +++++++++++++++++++++++++++ apps/patchwork/views/api.py | 36 ++++++++++++++++++++++++++++++++++++ patchwork/urls.py | 12 ++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 apps/patchwork/serializers.py create mode 100644 apps/patchwork/views/api.py diff --git a/apps/patchwork/serializers.py b/apps/patchwork/serializers.py new file mode 100644 index 0000000..f210af3 --- /dev/null +++ b/apps/patchwork/serializers.py @@ -0,0 +1,27 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2014 Intel Corporation +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# 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 +from rest_framework import serializers + +class ProjectSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Project + fields = ('name', 'linkname', 'listemail', 'web_url', 'scm_url', + 'webscm_url') diff --git a/apps/patchwork/views/api.py b/apps/patchwork/views/api.py new file mode 100644 index 0000000..30b42c2 --- /dev/null +++ b/apps/patchwork/views/api.py @@ -0,0 +1,36 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2014 Intel Corporation +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# 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 +from rest_framework import viewsets +from rest_framework.response import Response +from patchwork.serializers import ProjectSerializer + +class ProjectViewSet(viewsets.ViewSet): + model = Project + + def list(self, request): + queryset = Project.objects.all() + serializer = ProjectSerializer(queryset, many=True) + return Response(serializer.data) + + def retrieve(self, request, pk=None): + queryset = Project.objects.get(name=pk) + serializer = ProjectSerializer(queryset) + return Response(serializer.data) diff --git a/patchwork/urls.py b/patchwork/urls.py index b28eb90..e7a0c85 100644 --- a/patchwork/urls.py +++ b/patchwork/urls.py @@ -21,12 +21,24 @@ from django.conf.urls import patterns, url, include from django.conf import settings from django.contrib import admin from django.contrib.auth import views as auth_views +from rest_framework_nested import routers +import patchwork.views.api as api + +# API + +# /projects/$project/ +project_router = routers.SimpleRouter() +project_router.register('projects', api.ProjectViewSet) admin.autodiscover() urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), + # API + (r'^api/1.0/', include(project_router.urls)), + + # Example: (r'^$', 'patchwork.views.projects'), (r'^project/(?P[^/]+)/list/$', 'patchwork.views.patch.list'), (r'^project/(?P[^/]+)/$', 'patchwork.views.project.project'),