backend/app/users/api/views.py

86 lines
2.4 KiB
Python
Raw Normal View History

from rest_framework import generics
2022-10-08 16:02:57 +03:00
from rest_framework.generics import get_object_or_404
from rest_framework.permissions import IsAuthenticated
from common.permissions import IsAdmin
2022-10-08 16:02:57 +03:00
from users.api.serializers import (
UserSerializer,
DepartmentSerializer,
StreamSerializer,
CommandSerializer,
CreateSeasonSerializer,
ClanSerializer,
2022-10-08 16:02:57 +03:00
)
from users.models import User, Department, Stream, Command, Clan
class ListCreateUserApi(generics.ListCreateAPIView):
serializer_class = UserSerializer
permission_classes = [IsAuthenticated, IsAdmin]
queryset = User.objects.all()
2022-10-08 17:14:19 +03:00
class CreateSeasonApi(generics.CreateAPIView):
serializer_class = CreateSeasonSerializer
2022-10-08 19:33:58 +03:00
# permission_classes = [IsAuthenticated, IsAdmin]
2022-10-08 17:16:16 +03:00
class RetrieveUpdateDeleteUserApi(generics.RetrieveUpdateDestroyAPIView):
2022-10-08 16:02:57 +03:00
def get_object(self):
user = get_object_or_404(
User,
username=self.request.parser_context["kwargs"]["username"],
)
return user
serializer_class = UserSerializer
permission_classes = [IsAuthenticated, IsAdmin]
queryset = User.objects.all()
class ListCreateDepartmentApi(generics.ListCreateAPIView):
serializer_class = DepartmentSerializer
permission_classes = [IsAuthenticated, IsAdmin]
queryset = Department.objects.all()
class RetrieveUpdateDeleteDepartmentApi(generics.RetrieveUpdateDestroyAPIView):
2022-10-08 16:02:57 +03:00
lookup_field = "pk"
serializer_class = DepartmentSerializer
permission_classes = [IsAuthenticated, IsAdmin]
queryset = Department.objects.all()
class ListCreateStreamApi(ListCreateDepartmentApi):
serializer_class = StreamSerializer
queryset = Stream.objects.all()
class RetrieveUpdateDeleteStreamApi(RetrieveUpdateDeleteDepartmentApi):
2022-10-08 16:02:57 +03:00
serializer_class = StreamSerializer
queryset = Stream.objects.all()
class ListCreateCommandApi(ListCreateDepartmentApi):
serializer_class = CommandSerializer
queryset = Command.objects.all()
class RetrieveUpdateDeleteCommandApi(RetrieveUpdateDeleteDepartmentApi):
2022-10-08 16:02:57 +03:00
serializer_class = CommandSerializer
queryset = Command.objects.all()
class ListClansApiView(generics.ListAPIView):
serializer_class = ClanSerializer
queryset = Clan.objects.all()
permission_classes = [IsAuthenticated, IsAdmin]
2022-10-09 06:27:35 +03:00
class GetSelfUserApi(generics.RetrieveAPIView):
def get_object(self):
return self.request.user
permission_classes = [IsAuthenticated]
serializer_class = UserSerializer