1 from rest_framework.generics import RetrieveAPIView, RetrieveUpdateAPIView, ListAPIView, ListCreateAPIView
2 from rest_framework.permissions import IsAuthenticatedOrReadOnly
3 from django.http import Http404
5 from . import serializers
8 class BookList(ListAPIView):
9 serializer_class = serializers.BookSerializer
10 search_fields = ['title']
12 def get_queryset(self):
13 return models.Book.get_visible_for(self.request.user)
16 class BookDetail(RetrieveAPIView):
17 serializer_class = serializers.BookDetailSerializer
19 def get_queryset(self):
20 return models.Book.get_visible_for(self.request.user)
23 class ChunkList(ListAPIView):
24 queryset = models.Chunk.objects.all()
25 serializer_class = serializers.ChunkSerializer
26 filterset_fields = ['user', 'stage']
32 def get_queryset(self):
33 return models.Chunk.get_visible_for(self.request.user)
36 class ChunkDetail(RetrieveUpdateAPIView):
37 permission_classes = [IsAuthenticatedOrReadOnly]
38 serializer_class = serializers.ChunkDetailSerializer
40 def get_queryset(self):
41 return models.Chunk.get_visible_for(self.request.user)
44 class ChunkRevisionList(ListCreateAPIView):
45 permission_classes = [IsAuthenticatedOrReadOnly]
46 serializer_class = serializers.RevisionSerializer
48 def get_serializer_class(self):
49 if self.request.method == 'POST':
50 return serializers.RevisionDetailSerializer
52 return serializers.RevisionSerializer
54 def get_serializer_context(self):
55 ctx = super().get_serializer_context()
57 ctx["chunk"] = models.Chunk.objects.get(pk=self.kwargs['pk'])
58 except models.Chunk.DoesNotExist:
62 def get_queryset(self):
64 return models.Chunk.get_visible_for(self.request.user).get(
67 except models.Chunk.DoesNotExist:
71 class RevisionDetail(RetrieveAPIView):
72 queryset = models.Chunk.change_model.objects.all()
73 serializer_class = serializers.RevisionDetailSerializer
75 def get_queryset(self):
76 return models.Chunk.get_revisions_visible_for(self.request.user)