backend/app/users/api/views.py

71 lines
2.1 KiB
Python
Raw Permalink 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 17:14:19 +03:00
from users.api.serializers import UserSerializer, CreateSeasonSerializer
from users.models import User
2022-10-08 16:02:57 +03:00
from users.api.serializers import (
UserSerializer,
DepartmentSerializer,
StreamSerializer,
CommandSerializer,
)
from users.models import User, Department, Stream, Command
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
#permission_classes = [IsAuthenticated, IsAdmin]
2022-10-08 17:16:16 +03:00
2022-10-08 16:02:57 +03:00
class RetireUpdateDeleteUserApi(generics.RetrieveUpdateDestroyAPIView):
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 RetireUpdateDeleteDepartmentApi(generics.RetrieveUpdateDestroyAPIView):
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 RetireUpdateDeleteStreamApi(RetireUpdateDeleteDepartmentApi):
serializer_class = StreamSerializer
queryset = Stream.objects.all()
class ListCreateCommandApi(ListCreateDepartmentApi):
serializer_class = CommandSerializer
queryset = Command.objects.all()
class RetireUpdateDeleteCommandApi(RetireUpdateDeleteDepartmentApi):
serializer_class = CommandSerializer
queryset = Command.objects.all()