From f7627926cbfdee58be737828a7d5a01acabdd541 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 6 May 2021 13:08:21 +0200 Subject: [PATCH] Replace detail_route with action decorator DRF 3.10.0 deprecates the detail_route decorator in favor of action --- orchestra/api/actions.py | 4 ++-- orchestra/contrib/bills/api.py | 6 +++--- orchestra/contrib/domains/api.py | 10 +++++----- orchestra/contrib/issues/api.py | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/orchestra/api/actions.py b/orchestra/api/actions.py index 8e2c3531..d1b90264 100644 --- a/orchestra/api/actions.py +++ b/orchestra/api/actions.py @@ -1,12 +1,12 @@ from rest_framework import status -from rest_framework.decorators import detail_route +from rest_framework.decorators import action from rest_framework.response import Response from .serializers import SetPasswordSerializer class SetPasswordApiMixin(object): - @detail_route(methods=['post'], serializer_class=SetPasswordSerializer) + @action(detail=True, methods=['post'], serializer_class=SetPasswordSerializer) def set_password(self, request, pk): obj = self.get_object() data = request.data diff --git a/orchestra/contrib/bills/api.py b/orchestra/contrib/bills/api.py index 6bb16a85..7d050b4c 100644 --- a/orchestra/contrib/bills/api.py +++ b/orchestra/contrib/bills/api.py @@ -1,6 +1,6 @@ from django.http import HttpResponse from rest_framework import viewsets -from rest_framework.decorators import detail_route +from rest_framework.decorators import action from orchestra.api import router, LogApiMixin from orchestra.contrib.accounts.api import AccountApiMixin @@ -14,8 +14,8 @@ from .serializers import BillSerializer class BillViewSet(LogApiMixin, AccountApiMixin, viewsets.ModelViewSet): queryset = Bill.objects.all() serializer_class = BillSerializer - - @detail_route(methods=['get']) + + @action(detail=True, methods=['get']) def document(self, request, pk): bill = self.get_object() content_type = request.META.get('HTTP_ACCEPT') diff --git a/orchestra/contrib/domains/api.py b/orchestra/contrib/domains/api.py index 38ab2e40..27a25453 100644 --- a/orchestra/contrib/domains/api.py +++ b/orchestra/contrib/domains/api.py @@ -1,5 +1,5 @@ from rest_framework import viewsets -from rest_framework.decorators import detail_route +from rest_framework.decorators import action from rest_framework.response import Response from orchestra.api import router @@ -14,18 +14,18 @@ class DomainViewSet(AccountApiMixin, viewsets.ModelViewSet): serializer_class = DomainSerializer filter_fields = ('name',) queryset = Domain.objects.all() - + def get_queryset(self): qs = super(DomainViewSet, self).get_queryset() return qs.prefetch_related('records') - - @detail_route() + + @action(detail=True) def view_zone(self, request, pk=None): domain = self.get_object() return Response({ 'zone': domain.render_zone() }) - + def options(self, request): metadata = super(DomainViewSet, self).options(request) names = ['DOMAINS_DEFAULT_A', 'DOMAINS_DEFAULT_MX', 'DOMAINS_DEFAULT_NS'] diff --git a/orchestra/contrib/issues/api.py b/orchestra/contrib/issues/api.py index 15974a11..bbc5d5ee 100644 --- a/orchestra/contrib/issues/api.py +++ b/orchestra/contrib/issues/api.py @@ -1,5 +1,5 @@ from rest_framework import viewsets, mixins -from rest_framework.decorators import detail_route +from rest_framework.decorators import action from rest_framework.response import Response from orchestra.api import router, LogApiMixin @@ -12,19 +12,19 @@ from .serializers import TicketSerializer, QueueSerializer class TicketViewSet(LogApiMixin, viewsets.ModelViewSet): queryset = Ticket.objects.all() serializer_class = TicketSerializer - - @detail_route() + + @action(detail=True) def mark_as_read(self, request, pk=None): ticket = self.get_object() ticket.mark_as_read_by(request.user) return Response({'status': 'Ticket marked as read'}) - - @detail_route() + + @action(detail=True) def mark_as_unread(self, request, pk=None): ticket = self.get_object() ticket.mark_as_unread_by(request.user) return Response({'status': 'Ticket marked as unread'}) - + def get_queryset(self): qs = super(TicketViewSet, self).get_queryset() qs = qs.select_related('creator', 'queue')