Skip to content

Commit

Permalink
Changed requirement structure generation to be function-based
Browse files Browse the repository at this point in the history
 - Renamed some functions so they would make more sense.
 - Updated tests accordingly.
   - Added missing assert statement in
     `test_are_course_requirements_fulfilled`.
  • Loading branch information
KYDronePilot committed Dec 12, 2019
1 parent 62b9957 commit 779f6d9
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 190 deletions.
3 changes: 2 additions & 1 deletion src/backend/csc_440_project_backend/grades/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from grades.models import Course, CourseInstance, GradeEntry, Category, CategoryScoreRequirement, Semester, \
Requirement, College, Major, Concentration
from grades.models.requirement import get_requirements_structure
from grades.serializers import CourseSerializer, CourseInstanceSerializer, GradeEntrySerializer, CategorySerializer, \
CollegeSerializer, CategoryScoreRequirementSerializer, SemesterSerializer, CourseInstanceSearchSerializer, \
RequirementStructureSerializer, MajorSerializer, ConcentrationSerializer
Expand Down Expand Up @@ -203,7 +204,7 @@ def retrieve(self, request, *args, **kwargs):
# return Response(status=status.HTTP_404_NOT_FOUND)
queryset = Requirement.objects.get(concentration_id=self.kwargs['pk'])
# queryset = Requirement.objects.get(concentration_id=self.request.query_params['concentration'])
data = queryset.get_requirements_structure(self.request.user)
data = get_requirements_structure(queryset, self.request.user)
serializer = RequirementStructureSerializer(data)
return Response(serializer.data)

Expand Down
28 changes: 15 additions & 13 deletions src/backend/csc_440_project_backend/grades/models/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@ class Course(Common):
default=False
)

def is_completed(self, student):
"""
Check if the course was completed by a student.
def __str__(self):
return f'{self.code}{", deprecated" if self.is_deprecated else ""}'

Notes:
TODO: This method should not be used. It is highly inefficient for course completion checking

Args:
student: Student to check
def is_completed(course: Course, student):
"""
Check if a course was completed by a student.
Returns:
Whether the student completed the course
"""
return self.course_instances.filter(students=student).exists()
Notes:
TODO: This method should not be used. It is highly inefficient for course completion checking
def __str__(self):
return f'{self.code}{", deprecated" if self.is_deprecated else ""}'
Args:
course: Course instance
student: Student to check
Returns:
Whether the student completed the course
"""
return course.course_instances.filter(students=student).exists()
Loading

0 comments on commit 779f6d9

Please sign in to comment.