summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2016-06-16 16:13:17 -0500
committerStephen Finucane <stephen.finucane@intel.com>2016-06-27 18:19:08 +0100
commit92b6e6a39595841782b967e34e9b3bdebefbf1ec (patch)
tree3846790c3aea7cf5f8c7e093cfd6c1942fa353af
parent6f283ef361bd58120a527b917a18d4207053f348 (diff)
downloadpatchwork-92b6e6a39595841782b967e34e9b3bdebefbf1ec.tar
patchwork-92b6e6a39595841782b967e34e9b3bdebefbf1ec.tar.gz
REST: Add base configuration hooks for a REST API
This adds the ability to expose a REST API based on the Django REST framework project. Since this project isn't packaged in most current distributions, we ensure that its both installed and enabled before trying to use it. Signed-off-by: Andy Doan <andy.doan@linaro.org> Inspired-by: Damien Lespiau <damien.lespiau@intel.com> Reviewed-by: Stephen Finucane <stephen.finucane@intel.com>
-rw-r--r--patchwork/settings/base.py11
-rw-r--r--patchwork/settings/dev.py2
-rw-r--r--patchwork/urls.py9
-rw-r--r--patchwork/views/rest_api.py22
-rw-r--r--requirements-test.txt1
5 files changed, 45 insertions, 0 deletions
diff --git a/patchwork/settings/base.py b/patchwork/settings/base.py
index 2f81d4b..14f3209 100644
--- a/patchwork/settings/base.py
+++ b/patchwork/settings/base.py
@@ -28,6 +28,14 @@ INSTALLED_APPS = [
'patchwork',
]
+try:
+ # django rest framework isn't a standard package in most distros, so
+ # don't make it compulsory
+ import rest_framework # NOQA
+ INSTALLED_APPS += ['rest_framework']
+except ImportError:
+ pass
+
# HTTP
MIDDLEWARE_CLASSES = [
@@ -148,6 +156,9 @@ NOTIFICATION_FROM_EMAIL = DEFAULT_FROM_EMAIL
# Set to True to enable the Patchwork XML-RPC interface
ENABLE_XMLRPC = False
+# Set to True to enable the Patchwork REST API
+ENABLE_REST_API = False
+
# Set to True to enable redirections or URLs from previous versions
# of patchwork
COMPAT_REDIR = True
diff --git a/patchwork/settings/dev.py b/patchwork/settings/dev.py
index 8cf0526..e5c88d2 100644
--- a/patchwork/settings/dev.py
+++ b/patchwork/settings/dev.py
@@ -86,3 +86,5 @@ if django.VERSION >= (1, 7):
#
ENABLE_XMLRPC = True
+
+ENABLE_REST_API = True
diff --git a/patchwork/urls.py b/patchwork/urls.py
index f664501..2318ab9 100644
--- a/patchwork/urls.py
+++ b/patchwork/urls.py
@@ -143,6 +143,15 @@ if settings.ENABLE_XMLRPC:
name='pwclientrc'),
]
+if settings.ENABLE_REST_API:
+ if 'rest_framework' not in settings.INSTALLED_APPS:
+ raise RuntimeError(
+ 'djangorestframework must be installed to enable the REST API.')
+ import patchwork.views.rest_api
+ urlpatterns += [
+ url(r'^api/1.0/', include(patchwork.views.rest_api.router.urls)),
+ ]
+
# redirect from old urls
if settings.COMPAT_REDIR:
urlpatterns += [
diff --git a/patchwork/views/rest_api.py b/patchwork/views/rest_api.py
new file mode 100644
index 0000000..5436ed6
--- /dev/null
+++ b/patchwork/views/rest_api.py
@@ -0,0 +1,22 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2016 Linaro 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 rest_framework import routers
+
+router = routers.DefaultRouter()
diff --git a/requirements-test.txt b/requirements-test.txt
index 2d0b32c..b5f976c 100644
--- a/requirements-test.txt
+++ b/requirements-test.txt
@@ -2,3 +2,4 @@ mysqlclient==1.3.7 # replace this with psycopg2 for a PostgreSQL backend
django-debug-toolbar==1.4
python-dateutil>2.0,<3.0
selenium>2.0,<3.0
+djangorestframework>=3.3,<3.4