Skip to content
Snippets Groups Projects
Verified Commit db913d06 authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

refactor: remove code for nested routes

parent 51abe312
No related branches found
No related tags found
No related merge requests found
......@@ -28,13 +28,12 @@ from django_filters.rest_framework import DjangoFilterBackend
from drf_spectacular.utils import OpenApiResponse, extend_schema, extend_schema_view
from rest_framework import filters as drf_filters
from rest_framework import mixins, permissions, status, viewsets
from rest_framework.exceptions import ValidationError
from rest_framework.pagination import LimitOffsetPagination
from rest_framework.response import Response
from django.contrib.auth.models import User
from django.db import IntegrityError
from django.http import Http404, HttpResponse, JsonResponse
from django.http import HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404
from django.utils import timezone
from django.utils.translation import gettext as _
......@@ -730,27 +729,6 @@ class APINoteViewSet(
else:
return Note.objects.filter(timeslot__schedule__show__owners=user)
def _get_timeslot(self):
# TODO: Once we remove nested routes, timeslot ownership
# should be checked in a permission class.
timeslot_pk = self.request.data.get("timeslot_id", None)
if timeslot_pk is None:
timeslot_pk = get_values(self.kwargs, "timeslot_pk")
if timeslot_pk is None:
raise ValidationError({"timeslot_id": [_("This field is required.")]}, code="required")
qs = TimeSlot.objects.all()
if not self.request.user.is_superuser:
qs = qs.filter(schedule__show__owners=self.request.user)
try:
return qs.get(pk=timeslot_pk)
except TimeSlot.DoesNotExist:
raise Http404()
def perform_create(self, serializer):
# TODO: Once we remove nested routes, this should be removed
# and timeslot should be required in the serializer again.
serializer.save(timeslot=self._get_timeslot())
class ActiveFilterMixin:
filter_class = filters.ActiveFilterSet
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment