40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
|
from rest_framework.response import Response
|
||
|
from rest_framework.views import APIView
|
||
|
from rest_framework.exceptions import NotFound
|
||
|
from rest_framework.permissions import IsAuthenticated
|
||
|
|
||
|
from apps.archive.models import CreatorModel
|
||
|
|
||
|
from .serializers import (
|
||
|
CreatorListSerializer,
|
||
|
CreatorDetailsSerializer,
|
||
|
)
|
||
|
|
||
|
|
||
|
class CreatorListView(APIView):
|
||
|
permission_classes = [IsAuthenticated]
|
||
|
|
||
|
def get(self, request):
|
||
|
user = request.user.userprofile
|
||
|
|
||
|
if user.show_mature:
|
||
|
creators = CreatorModel.objects.all()
|
||
|
else:
|
||
|
creators = CreatorModel.objects.filter(mature=False)
|
||
|
|
||
|
serializer = CreatorListSerializer(creators, many=True)
|
||
|
return Response(serializer.data)
|
||
|
|
||
|
|
||
|
class CreatorDetailsView(APIView):
|
||
|
permission_classes = [IsAuthenticated]
|
||
|
|
||
|
def get(self, request, creator_id):
|
||
|
try:
|
||
|
creator = CreatorModel.objects.get(creator_id=creator_id)
|
||
|
except CreatorModel.DoesNotExist:
|
||
|
raise NotFound(detail="Creator not found.")
|
||
|
|
||
|
serializer = CreatorDetailsSerializer(creator)
|
||
|
return Response(serializer.data)
|