Improved subject viewsets and subjects postmigration script

This commit is contained in:
Keannu Bernasol 2023-07-25 16:29:11 +08:00
parent 6af2bd0c0d
commit 8537b1d3ac
3 changed files with 19 additions and 2 deletions

View file

@ -106,7 +106,7 @@ def populate_subjects(sender, **kwargs):
subject_year_level = year_term[0].strip()
subject_semester = year_term[1].strip()
subject_code = row[1]
subject_name = row[2]
subject_name = row[2].replace("\n", " ")
# Definitions of subjects to ignore
ignored_subject_codes = ['NSTP', 'ROTC', 'CWTS', 'LTS']

View file

@ -1,8 +1,10 @@
from django.urls import include, path
from .views import SubjectByCourseYearSemesterView, SubjectListView
from .views import SubjectByCourseView, SubjectByCourseYearSemesterView, SubjectListView
from rest_framework import routers
urlpatterns = [
path('', SubjectListView.as_view()),
path('<slug:course_slug>',
SubjectByCourseView.as_view()),
path('<slug:course_slug>/<slug:year_slug>/<slug:semester_slug>',
SubjectByCourseYearSemesterView.as_view()),
]

View file

@ -10,6 +10,21 @@ class SubjectListView(generics.ListAPIView):
queryset = Subject.objects.all()
class SubjectByCourseView(generics.ListAPIView):
queryset = Subject.objects.all()
serializer_class = SubjectSerializer
def get(self, request, course_slug):
# Retrieve the subjects based on year level and semester slugs
subjects = Subject.objects.filter(
courses__shortname=course_slug).order_by('-subjectyearlevel')
# Serialize the subjects
serializer = SubjectSerializer(subjects, many=True)
return Response(serializer.data)
class SubjectByCourseYearSemesterView(generics.ListAPIView):
queryset = Subject.objects.all()
serializer_class = SubjectSerializer