diff options
author | Stephen Finucane <stephen@that.guru> | 2017-04-27 00:58:03 +0100 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2017-04-28 23:52:04 +0100 |
commit | 5094cfdbf0b11af44f979b16e43e8cce36378322 (patch) | |
tree | 9b95ee6b274c991ea21371fd4c842b1e22ffc4f7 | |
parent | f75be7ed94ab98769b1c1fbcdef80a1c643724d5 (diff) | |
download | patchwork-5094cfdbf0b11af44f979b16e43e8cce36378322.tar patchwork-5094cfdbf0b11af44f979b16e43e8cce36378322.tar.gz |
REST: Fix versioning
One of the few remaining warts in the API is versioning. There is some
basic versioning there, but it doesn't work properly as-is. Fix this by
correcting the index endpoint ('/') to use Django REST Framework's
'reverse' function [1], which handles versioning for us [2] and
switching from 'NamespaceVersioning' to 'URLPathVersioning', the latter
of which does the same thing but in a different way.
[1] http://www.django-rest-framework.org/api-guide/reverse/#reverse
[2] http://www.django-rest-framework.org/api-guide/versioning/#reversing-urls-for-versioned-apis
[3] http://www.django-rest-framework.org/api-guide/versioning/#urlpathversioning
Signed-off-by: Stephen Finucane <stephen@that.guru>
-rw-r--r-- | patchwork/api/check.py | 4 | ||||
-rw-r--r-- | patchwork/api/event.py | 2 | ||||
-rw-r--r-- | patchwork/api/index.py | 21 | ||||
-rw-r--r-- | patchwork/api/patch.py | 2 | ||||
-rw-r--r-- | patchwork/settings/base.py | 2 | ||||
-rw-r--r-- | patchwork/urls.py | 2 |
6 files changed, 16 insertions, 17 deletions
diff --git a/patchwork/api/check.py b/patchwork/api/check.py index 393fcf2..d368265 100644 --- a/patchwork/api/check.py +++ b/patchwork/api/check.py @@ -100,12 +100,12 @@ class CheckListCreate(CheckMixin, ListCreateAPIView): lookup_url_kwarg = 'patch_id' - def create(self, request, patch_id): + def create(self, request, patch_id, *args, **kwargs): p = Patch.objects.get(id=patch_id) if not p.is_editable(request.user): raise PermissionDenied() request.patch = p - return super(CheckListCreate, self).create(request) + return super(CheckListCreate, self).create(request, *args, **kwargs) class CheckDetail(CheckMixin, MultipleFieldLookupMixin, RetrieveAPIView): diff --git a/patchwork/api/event.py b/patchwork/api/event.py index 32b3bde..a060022 100644 --- a/patchwork/api/event.py +++ b/patchwork/api/event.py @@ -19,8 +19,8 @@ from collections import OrderedDict -from django.core.urlresolvers import reverse from rest_framework.generics import ListAPIView +from rest_framework.reverse import reverse from rest_framework.serializers import HyperlinkedModelSerializer from rest_framework.serializers import SerializerMethodField diff --git a/patchwork/api/index.py b/patchwork/api/index.py index 513e8b6..53494db 100644 --- a/patchwork/api/index.py +++ b/patchwork/api/index.py @@ -17,22 +17,21 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from django.core.urlresolvers import reverse from rest_framework.response import Response +from rest_framework.reverse import reverse from rest_framework.views import APIView class IndexView(APIView): - def get(self, request, format=None): + def get(self, request, *args, **kwargs): return Response({ - 'projects': request.build_absolute_uri( - reverse('api-project-list')), - 'users': request.build_absolute_uri(reverse('api-user-list')), - 'people': request.build_absolute_uri(reverse('api-person-list')), - 'patches': request.build_absolute_uri(reverse('api-patch-list')), - 'covers': request.build_absolute_uri(reverse('api-cover-list')), - 'series': request.build_absolute_uri(reverse('api-series-list')), - 'events': request.build_absolute_uri(reverse('api-event-list')), - 'bundles': request.build_absolute_uri(reverse('api-bundle-list')), + 'projects': reverse('api-project-list', request=request), + 'users': reverse('api-user-list', request=request), + 'people': reverse('api-person-list', request=request), + 'patches': reverse('api-patch-list', request=request), + 'covers': reverse('api-cover-list', request=request), + 'series': reverse('api-series-list', request=request), + 'events': reverse('api-event-list', request=request), + 'bundles': reverse('api-bundle-list', request=request), }) diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py index fa6fb46..1e5c13f 100644 --- a/patchwork/api/patch.py +++ b/patchwork/api/patch.py @@ -19,11 +19,11 @@ import email.parser -from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ from rest_framework.generics import ListAPIView from rest_framework.generics import RetrieveUpdateAPIView from rest_framework.relations import RelatedField +from rest_framework.reverse import reverse from rest_framework.serializers import HyperlinkedModelSerializer from rest_framework.serializers import SerializerMethodField diff --git a/patchwork/settings/base.py b/patchwork/settings/base.py index 5d5caf1..e6d34ba 100644 --- a/patchwork/settings/base.py +++ b/patchwork/settings/base.py @@ -144,7 +144,7 @@ except ImportError: REST_FRAMEWORK = { 'DEFAULT_VERSIONING_CLASS': - 'rest_framework.versioning.NamespaceVersioning', + 'rest_framework.versioning.URLPathVersioning', 'DEFAULT_PAGINATION_CLASS': 'patchwork.api.base.LinkHeaderPagination', 'DEFAULT_FILTER_BACKENDS': ( 'patchwork.compat.DjangoFilterBackend', diff --git a/patchwork/urls.py b/patchwork/urls.py index e888386..8c8c172 100644 --- a/patchwork/urls.py +++ b/patchwork/urls.py @@ -232,7 +232,7 @@ if settings.ENABLE_REST_API: ] urlpatterns += [ - url(r'^api/1.0/', include(api_patterns)), + url(r'^api/(?P<version>(1.0))/', include(api_patterns)), ] |