Skip to content

Commit

Permalink
add support for fulfilling with 3 digit codes/other courses in topic
Browse files Browse the repository at this point in the history
  • Loading branch information
AaDalal committed Apr 9, 2024
1 parent de949ac commit 2b340fc
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions backend/degree/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from textwrap import dedent

from django.db.models import Q
from django.db.models import Q, Subquery
from rest_framework import serializers

from courses.models import Course
Expand Down Expand Up @@ -143,13 +143,19 @@ def validate(self, data):
for rule in rules:
# NOTE: we don't do any validation if the course doesn't exist in DB. In future,
# it may be better to prompt user for manual override
if (
Course.objects.filter(full_code=full_code).exists()
and not Course.objects.filter(rule.get_q_object(), full_code=full_code).exists()
):
raise serializers.ValidationError(
f"Course {full_code} does not satisfy rule {rule.id}"
)
if (Course.objects.filter(full_code=full_code).exists()):
satisfying_courses = Course.objects.filter(rule.get_q_object())
if (
not (
Course.objects.filter(
full_code=full_code,
topic_id__in=Subquery(satisfying_courses.values('topic_id'))
).exists()
)
):
raise serializers.ValidationError(
f"Course {full_code} does not satisfy rule {rule.id}"
)

# Check for double count restrictions
double_count_restrictions = DoubleCountRestriction.objects.filter(
Expand Down

0 comments on commit 2b340fc

Please sign in to comment.