Verified Commit 407db0fb authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Change list_route detail_route decorators to action to solve DeprecationWarning

parent c77b1407
......@@ -2,8 +2,9 @@
from datetime import datetime
from django.utils import timezone
from pytz.exceptions import InvalidTimeError
from rest_framework import viewsets, filters
from rest_framework.decorators import list_route, detail_route
from rest_framework.decorators import action
from rest_framework.exceptions import ParseError, PermissionDenied, NotFound
from rest_framework.generics import get_object_or_404
from rest_framework.mixins import RetrieveModelMixin, UpdateModelMixin
......@@ -14,7 +15,6 @@ from rest_framework.permissions import (
)
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from pytz.exceptions import InvalidTimeError
from events import services
from events.api.permissions import UnpublishedEventPermissions
......@@ -89,7 +89,7 @@ class EventViewset(viewsets.ReadOnlyModelViewSet):
def get_serializer_context(self):
return super().get_serializer_context()
@detail_route(methods=['get', 'post'])
@action(detail=True, methods=['get', 'post'])
def registrations(self, request, pk):
"""
Defines a custom route for the event's registrations,
......@@ -137,7 +137,7 @@ class EventViewset(viewsets.ReadOnlyModelViewSet):
return Response(serializer.data)
@list_route(permission_classes=(IsAuthenticatedOrReadOnly,))
@action(detail=False, permission_classes=(IsAuthenticatedOrReadOnly,))
def calendarjs(self, request):
"""
Defines a custom route that outputs the correctly formatted
......@@ -158,7 +158,7 @@ class EventViewset(viewsets.ReadOnlyModelViewSet):
queryset, many=True, context={'member': request.member})
return Response(serializer.data)
@list_route(permission_classes=(IsAdminUser, UnpublishedEventPermissions,))
@action(detail=False, permission_classes=(IsAdminUser, UnpublishedEventPermissions,))
def unpublished(self, request):
"""
Defines a custom route that outputs the correctly formatted
......
import copy
from datetime import datetime
from django.utils import timezone
from pytz.exceptions import InvalidTimeError
from rest_framework import permissions
from rest_framework import viewsets, filters
from rest_framework.decorators import list_route
from rest_framework.decorators import action
from rest_framework.exceptions import ParseError
from rest_framework.response import Response
......@@ -53,7 +54,7 @@ class MemberViewset(viewsets.ReadOnlyModelViewSet):
birthdays.append(bday)
return birthdays
@list_route()
@action(detail=False)
def birthdays(self, request):
try:
start = timezone.make_aware(
......@@ -81,7 +82,7 @@ class MemberViewset(viewsets.ReadOnlyModelViewSet):
serializer = MemberBirthdaySerializer(birthdays, many=True)
return Response(serializer.data)
@list_route()
@action(detail=False)
def me(self, request):
kwargs = {
'context': self.get_serializer_context(),
......
from datetime import datetime
from django.utils import timezone
from pytz.exceptions import InvalidTimeError
from rest_framework import viewsets, filters
from rest_framework.decorators import list_route
from rest_framework.decorators import action
from rest_framework.exceptions import ParseError
from rest_framework.permissions import IsAuthenticatedOrReadOnly, \
IsAuthenticated
from rest_framework.response import Response
from pytz.exceptions import InvalidTimeError
from partners.api.serializers import PartnerEventCalendarJSSerializer, \
PartnerEventSerializer, PartnerSerializer
......@@ -31,7 +31,7 @@ class PartnerViewset(viewsets.ReadOnlyModelViewSet):
serializer_class = PartnerSerializer
queryset = Partner.objects.filter(is_active=True)
@list_route(permission_classes=(IsAuthenticatedOrReadOnly,))
@action(detail=False, permission_classes=(IsAuthenticatedOrReadOnly,))
def calendarjs(self, request):
end, start = _extract_date_range(request)
......
from django.db import IntegrityError
from rest_framework import permissions
from rest_framework.decorators import action
from rest_framework.exceptions import (ValidationError, NotFound,
PermissionDenied)
from rest_framework.generics import get_object_or_404
from rest_framework.viewsets import GenericViewSet, ModelViewSet
from rest_framework.mixins import ListModelMixin
from rest_framework.decorators import list_route
from rest_framework.response import Response
from rest_framework.exceptions import (ValidationError, NotFound,
PermissionDenied)
from rest_framework.viewsets import GenericViewSet, ModelViewSet
from pizzas.models import Product, PizzaEvent, Order
from pizzas.api import serializers
from pizzas.models import Product, PizzaEvent, Order
class PizzaViewset(GenericViewSet, ListModelMixin):
......@@ -28,7 +27,7 @@ class PizzaViewset(GenericViewSet, ListModelMixin):
return Response(serializer.data)
raise PermissionDenied
@list_route()
@action(detail=False)
def event(self, request):
event = PizzaEvent.current()
......
from django.utils.translation import get_language_from_request
from rest_framework import permissions
from rest_framework.decorators import list_route
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
......@@ -42,7 +42,7 @@ class DeviceViewSet(ModelViewSet):
def perform_update(self, serializer):
serializer.save(user=self.request.user)
@list_route()
@action(detail=False)
def categories(self, request):
categories = Category.objects.all()
serializer = CategorySerializer(categories, many=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment