Replace detail_route with action decorator

DRF 3.10.0 deprecates the detail_route decorator in favor of action
This commit is contained in:
Santiago L 2021-05-06 13:08:21 +02:00
parent ffd08459c4
commit f7627926cb
4 changed files with 16 additions and 16 deletions

View File

@ -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

View File

@ -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
@ -15,7 +15,7 @@ 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')

View File

@ -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
@ -19,7 +19,7 @@ class DomainViewSet(AccountApiMixin, viewsets.ModelViewSet):
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({

View File

@ -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
@ -13,13 +13,13 @@ 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)