2023-07-18 15:51:06 +08:00
|
|
|
from rest_framework import generics, viewsets
|
2023-07-26 12:14:19 +08:00
|
|
|
from .models import Subject, SubjectInstance
|
|
|
|
from .serializers import SubjectSerializer, SubjectInstanceSerializer
|
2023-06-27 18:15:31 +08:00
|
|
|
from rest_framework.views import APIView
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
|
|
|
|
|
|
|
class SubjectListView(generics.ListAPIView):
|
|
|
|
serializer_class = SubjectSerializer
|
|
|
|
queryset = Subject.objects.all()
|
|
|
|
|
|
|
|
|
2023-07-25 16:29:11 +08:00
|
|
|
class SubjectByCourseView(generics.ListAPIView):
|
2023-07-26 12:14:19 +08:00
|
|
|
queryset = SubjectInstance.objects.all()
|
|
|
|
serializer_class = SubjectInstanceSerializer
|
2023-07-25 16:29:11 +08:00
|
|
|
|
|
|
|
def get(self, request, course_slug):
|
2023-07-26 12:14:19 +08:00
|
|
|
# Retrieve the subjects based on course slug
|
|
|
|
subjects = SubjectInstance.objects.filter(
|
|
|
|
course__shortname=course_slug)
|
2023-07-25 16:29:11 +08:00
|
|
|
|
|
|
|
# Serialize the subjects
|
2023-07-26 12:14:19 +08:00
|
|
|
serializer = SubjectInstanceSerializer(subjects, many=True)
|
2023-07-25 16:29:11 +08:00
|
|
|
return Response(serializer.data)
|
|
|
|
|
|
|
|
|
2023-07-24 01:47:01 +08:00
|
|
|
class SubjectByCourseYearSemesterView(generics.ListAPIView):
|
2023-07-26 12:14:19 +08:00
|
|
|
queryset = SubjectInstance.objects.all()
|
2023-07-24 01:47:01 +08:00
|
|
|
serializer_class = SubjectSerializer
|
2023-06-27 21:35:19 +08:00
|
|
|
|
2023-07-17 21:23:27 +08:00
|
|
|
def get(self, request, course_slug, year_slug, semester_slug):
|
2023-06-27 21:35:19 +08:00
|
|
|
# Retrieve the subjects based on year level and semester slugs
|
2023-07-26 12:14:19 +08:00
|
|
|
subjects = SubjectInstance.objects.filter(
|
|
|
|
course__shortname=course_slug, year_level__shortname=year_slug, semester__shortname=semester_slug)
|
2023-06-27 21:35:19 +08:00
|
|
|
# Serialize the subjects
|
2023-07-26 12:14:19 +08:00
|
|
|
serializer = SubjectInstanceSerializer(subjects, many=True)
|
2023-06-27 21:35:19 +08:00
|
|
|
return Response(serializer.data)
|