2023-08-07 15:16:57 +08:00
|
|
|
from django.shortcuts import get_object_or_404
|
2023-06-27 13:40:31 +08:00
|
|
|
from rest_framework import generics, viewsets
|
2023-06-26 23:50:55 +08:00
|
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
|
from .models import StudentStatus
|
|
|
|
from .serializers import StudentStatusSerializer
|
|
|
|
|
|
|
|
|
2023-06-27 13:40:31 +08:00
|
|
|
class StudentStatusAPIView(generics.RetrieveUpdateAPIView):
|
2023-06-26 23:50:55 +08:00
|
|
|
serializer_class = StudentStatusSerializer
|
|
|
|
permission_classes = [IsAuthenticated]
|
|
|
|
|
2023-08-06 14:19:55 +08:00
|
|
|
def get_queryset(self):
|
2023-06-26 23:50:55 +08:00
|
|
|
user = self.request.user
|
2023-08-06 14:19:55 +08:00
|
|
|
queryset = StudentStatus.objects.filter(user=user)
|
|
|
|
return queryset
|
2023-06-26 23:50:55 +08:00
|
|
|
|
2023-08-07 15:16:57 +08:00
|
|
|
def get_object(self):
|
|
|
|
queryset = self.get_queryset()
|
|
|
|
obj = get_object_or_404(queryset)
|
|
|
|
return obj
|
|
|
|
|
2023-06-26 23:50:55 +08:00
|
|
|
|
|
|
|
class ActiveStudentStatusListAPIView(generics.ListAPIView):
|
|
|
|
serializer_class = StudentStatusSerializer
|
2023-08-15 14:14:26 +08:00
|
|
|
# permission_classes = [IsAuthenticated]
|
2023-06-26 23:50:55 +08:00
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
user = self.request.user
|
2023-08-15 14:14:26 +08:00
|
|
|
return StudentStatus.objects.filter(active=True and user != user)
|