replace list_route() and detail_route() with action()

This commit is contained in:
Laura Klünder 2018-11-23 18:12:03 +01:00
parent be0531415d
commit c5d8315d97
3 changed files with 18 additions and 18 deletions

View file

@ -4,7 +4,7 @@ from django.db.models import Prefetch, Q
from django.urls import Resolver404, resolve
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from rest_framework.decorators import detail_route, list_route
from rest_framework.decorators import action
from rest_framework.exceptions import NotFound, PermissionDenied, ValidationError
from rest_framework.generics import get_object_or_404
from rest_framework.response import Response
@ -75,7 +75,7 @@ class EditorViewSet(ViewSet):
return levels, levels_on_top, levels_under
# noinspection PyPep8Naming
@list_route(methods=['get'])
@action(detail=False, methods=['get'])
@api_etag(etag_func=etag_func, cache_parameters={'level': str, 'space': str})
def geometries(self, request, *args, **kwargs):
if not can_access_editor(request):
@ -232,7 +232,7 @@ class EditorViewSet(ViewSet):
else:
raise ValidationError('No level or space specified.')
@list_route(methods=['get'])
@action(detail=False, methods=['get'])
@api_etag(etag_func=MapUpdate.current_cache_key, cache_parameters={})
def geometrystyles(self, request, *args, **kwargs):
if not can_access_editor(request):
@ -257,7 +257,7 @@ class EditorViewSet(ViewSet):
'wifimeasurement': '#DDDD00',
})
@list_route(methods=['get'])
@action(detail=False, methods=['get'])
@api_etag(etag_func=etag_func, cache_parameters={})
def bounds(self, request, *args, **kwargs):
if not can_access_editor(request):
@ -344,14 +344,14 @@ class ChangeSetViewSet(ReadOnlyModelViewSet):
return PermissionDenied
return Response(self.get_object().serialize())
@list_route(methods=['get'])
@action(detail=False, methods=['get'])
def current(self, request, *args, **kwargs):
if not can_access_editor(request):
return PermissionDenied
changeset = ChangeSet.get_for_request(request)
return Response(changeset.serialize())
@detail_route(methods=['get'])
@action(detail=True, methods=['get'])
def changes(self, request, *args, **kwargs):
if not can_access_editor(request):
return PermissionDenied

View file

@ -12,7 +12,7 @@ from django.utils.cache import get_conditional_response
from django.utils.http import http_date, quote_etag, urlsafe_base64_encode
from django.utils.translation import get_language
from django.utils.translation import ugettext_lazy as _
from rest_framework.decorators import detail_route, list_route
from rest_framework.decorators import action
from rest_framework.exceptions import NotFound, ValidationError
from rest_framework.mixins import RetrieveModelMixin
from rest_framework.response import Response
@ -84,7 +84,7 @@ class MapViewSet(ViewSet):
/bounds/ returns the maximum bounds of the map
"""
@list_route(methods=['get'])
@action(detail=False, methods=['get'])
@api_etag(permissions=False, cache_parameters={})
def bounds(self, request, *args, **kwargs):
return Response({
@ -205,7 +205,7 @@ class LevelViewSet(MapdataViewSet):
"""
queryset = Level.objects.all()
@list_route(methods=['get'])
@action(detail=False, methods=['get'])
@api_etag(permissions=False, cache_parameters={})
def geometrytypes(self, request):
return self.list_types(get_submodels(LevelGeometryMixin))
@ -225,7 +225,7 @@ class SpaceViewSet(MapdataViewSet):
queryset = Space.objects.all()
base_mapdata = True
@list_route(methods=['get'])
@action(detail=False, methods=['get'])
@api_etag(permissions=False, cache_parameters={})
def geometrytypes(self, request):
return self.list_types(get_submodels(SpaceGeometryMixin))
@ -329,7 +329,7 @@ class LocationViewSetBase(RetrieveModelMixin, GenericViewSet):
geometry=geometry and MapdataViewSet.can_access_geometry(request, location),
simple_geometry=True))
@detail_route(methods=['get'])
@action(detail=True, methods=['get'])
@api_etag(base_mapdata_check=True)
def details(self, request, **kwargs):
location = self.get_object()
@ -391,7 +391,7 @@ class LocationViewSet(LocationViewSetBase):
return Response(result)
@list_route(methods=['get'])
@action(detail=False, methods=['get'])
@api_etag(permissions=False)
def types(self, request):
return MapdataViewSet.list_types(get_submodels(Location), geomtype=False)
@ -410,7 +410,7 @@ class SourceViewSet(MapdataViewSet):
queryset = Source.objects.all()
order_by = ('name',)
@detail_route(methods=['get'])
@action(detail=True, methods=['get'])
def image(self, request, pk=None):
return self._image(request, pk=pk)
@ -439,7 +439,7 @@ class UpdatesViewSet(GenericViewSet):
Set the tile access cookie.
The tile access cookie is only valid for 1 minute, so if you are displaying a map, call this endpoint repeatedly.
"""
@list_route(methods=['get'])
@action(detail=False, methods=['get'])
def fetch(self, request, key=None):
cross_origin = request.META.get('HTTP_ORIGIN')
if cross_origin is not None:

View file

@ -1,6 +1,6 @@
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from rest_framework.decorators import list_route
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.viewsets import ViewSet
@ -19,7 +19,7 @@ class RoutingViewSet(ViewSet):
/options/ Get or set route options.
/locate/ Wifi locate.
"""
@list_route(methods=['get', 'post'])
@action(detail=False, methods=['get', 'post'])
def route(self, request, *args, **kwargs):
params = request.POST if request.method == 'POST' else request.GET
form = RouteForm(params, request=request)
@ -64,7 +64,7 @@ class RoutingViewSet(ViewSet):
'result': route.serialize(locations=visible_locations_for_request(request)),
})
@list_route(methods=['get', 'post'])
@action(detail=False, methods=['get', 'post'])
def options(self, request, *args, **kwargs):
options = RouteOptions.get_for_request(request)
@ -79,7 +79,7 @@ class RoutingViewSet(ViewSet):
return Response(options.serialize())
@list_route(methods=('POST', ))
@action(detail=False, methods=('POST', ))
def locate(self, request, *args, **kwargs):
try:
location = Locator.load().locate(request.data, permissions=AccessPermission.get_for_request(request))