Fix: the creators api views for the last commit
This commit is contained in:
parent
27c7fee6ad
commit
2b116ac801
1 changed files with 16 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
||||||
|
from rest_framework.generics import ListAPIView, RetrieveAPIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
|
||||||
from rest_framework.exceptions import NotFound
|
from rest_framework.exceptions import NotFound
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
|
||||||
|
@ -11,29 +11,28 @@ from .serializers import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CreatorListView(APIView):
|
class CreatorListView(ListAPIView):
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
serializer_class = CreatorListSerializer
|
||||||
|
|
||||||
def get(self, request):
|
def get_queryset(self):
|
||||||
user = request.user.userprofile
|
user = self.request.user.userprofile
|
||||||
|
|
||||||
if user.show_mature:
|
if user.show_mature:
|
||||||
creators = CreatorModel.objects.all()
|
return CreatorModel.objects.all()
|
||||||
else:
|
else:
|
||||||
creators = CreatorModel.objects.filter(mature=False)
|
return CreatorModel.objects.filter(mature=False)
|
||||||
|
|
||||||
serializer = CreatorListSerializer(creators, many=True)
|
|
||||||
return Response(serializer.data)
|
|
||||||
|
|
||||||
|
|
||||||
class CreatorDetailsView(APIView):
|
class CreatorDetailsView(RetrieveAPIView):
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
serializer_class = CreatorDetailsSerializer
|
||||||
|
lookup_field = "creator_id"
|
||||||
|
|
||||||
def get(self, request, creator_id):
|
def get_queryset(self):
|
||||||
try:
|
user = self.request.user.userprofile
|
||||||
creator = CreatorModel.objects.get(creator_id=creator_id)
|
|
||||||
except CreatorModel.DoesNotExist:
|
|
||||||
raise NotFound(detail="Creator not found.")
|
|
||||||
|
|
||||||
serializer = CreatorDetailsSerializer(creator)
|
if user.show_mature:
|
||||||
return Response(serializer.data)
|
return CreatorModel.objects.all()
|
||||||
|
else:
|
||||||
|
return CreatorModel.objects.filter(mature=False)
|
||||||
|
|
Loading…
Add table
Reference in a new issue