aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/views.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/api/views.py b/api/views.py
index b7b69e3..2459455 100644
--- a/api/views.py
+++ b/api/views.py
@@ -20,7 +20,7 @@ from django.db.models.functions import ExtractWeek, ExtractYear
from django.utils import timezone
from rest_framework import viewsets
-from rest_framework.decorators import action, detail_route
+from rest_framework.decorators import action
from rest_framework.response import Response
from ..forms import QSJPSForm
@@ -35,7 +35,7 @@ class YearViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Year.objects.all().order_by("name")
serializer_class = YearSerializer
- @detail_route(methods=["get"], url_path="timetables")
+ @action(detail=True, methods=["get"], url_path="timetables")
def timetable_list(self, request, pk):
year = self.get_object()
timetables = Timetable.objects.filter(year=year).distinct() \
@@ -49,7 +49,7 @@ class SourceViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Source.objects.all().order_by("pk")
serializer_class = SourceSerializer
- @detail_route(methods=["get"], url_path="timetables")
+ @action(detail=True, methods=["get"], url_path="timetables")
def timetable_list(self, request, pk):
source = self.get_object()
timetables = Timetable.objects.filter(source=source).distinct() \
@@ -64,7 +64,7 @@ class TimetableViewSet(viewsets.ReadOnlyModelViewSet):
.order_by("year", "name")
serializer_class = TimetableSerializer
- @detail_route(methods=["get"], url_path="groups")
+ @action(detail=True, methods=["get"], url_path="groups")
def group_list(self, request, pk):
timetable = self.get_object()
groups = Group.objects.filter(source=timetable.source).distinct() \
@@ -75,7 +75,7 @@ class TimetableViewSet(viewsets.ReadOnlyModelViewSet):
class CourseListGroupSet(viewsets.ReadOnlyModelViewSet):
- @detail_route(methods=["get"], url_path="courses")
+ @action(detail=True, methods=["get"], url_path="courses")
def course_list(self, request, pk):
obj = self.get_object()
courses = Course.objects.get_courses(obj).prefetch_related("groups")
@@ -91,14 +91,15 @@ class CourseListGroupSet(viewsets.ReadOnlyModelViewSet):
many=True)
return self.get_paginated_response(courses_json.data)
- @detail_route(methods=["get"], url_path="courses/days/current")
+ @action(detail=True, methods=["get"], url_path="courses/days/current")
def current_day(self, request, pk):
obj = self.get_object()
start = datetime.date.today()
end = start + datetime.timedelta(days=1)
return self.__get_courses(obj, start, end)
- @detail_route(methods=["get"], url_path="courses/days/(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)")
+ @action(detail=True, methods=["get"],
+ url_path="courses/days/(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)")
def other_day(self, request, pk, year, month, day):
obj = self.get_object()
@@ -116,14 +117,14 @@ class CourseListGroupSet(viewsets.ReadOnlyModelViewSet):
end = start + datetime.timedelta(days=1)
return self.__get_courses(obj, start, end)
- @detail_route(methods=["get"], url_path="courses/weeks/current")
+ @action(detail=True, methods=["get"], url_path="courses/weeks/current")
def current_week(self, request, pk):
obj = self.get_object()
start, end = get_week(*get_current_or_next_week())
return self.__get_courses(obj, start, end)
- @detail_route(methods=["get"],
- url_path="courses/weeks/(?P<year>\d+)/(?P<week>\d+)")
+ @action(detail=True, methods=["get"],
+ url_path="courses/weeks/(?P<year>\d+)/(?P<week>\d+)")
def other_week(self, request, pk, year, week):
obj = self.get_object()
@@ -142,7 +143,7 @@ class GroupViewSet(CourseListGroupSet):
queryset = Group.objects.all().order_by("name")
serializer_class = GroupSerializer
- @detail_route(methods=["get"], url_path="courses/weeks")
+ @action(detail=True, methods=["get"], url_path="courses/weeks")
def weeks(self, request, pk):
group = self.get_object()
groups = Group.objects.get_parents(group)