Skip to content

Commit

Permalink
refactor: some goofy logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Sep 11, 2024
1 parent 09d2464 commit 5b85875
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions course_discovery/apps/course_metadata/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ def available(self, exclude_hidden_runs=False):
Q(course_runs__status=CourseRunStatus.Published)
)

if exclude_hidden_runs:
# A CourseRun is "hidden" if it has a "hidden" attribute set to True.
marketable &= ~Q(course_runs__hidden=True)

# exclude() is intentionally avoided here. We want Courses to be included
# in the resulting queryset if at least one of their runs matches our availability
# criteria. For example, consider a Course with two CourseRuns; one of the
Expand All @@ -58,7 +54,12 @@ def available(self, exclude_hidden_runs=False):
# By itself, the query performs a join across several tables and would return
# the id of the same course multiple times (a separate copy for each available
# seat in each available run).
ids = self.filter(enrollable & not_ended & marketable).values('id').distinct()
if exclude_hidden_runs:
# A CourseRun is "hidden" if it has a "hidden" attribute set to True.
hidden = ~Q(course_runs__hidden=True)
ids = self.filter(enrollable & not_ended & marketable & hidden).values('id').distinct()
else:
ids = self.filter(enrollable & not_ended & marketable).values('id').distinct()

# Now return the full object for each of the selected ids
return self.filter(id__in=ids)
Expand Down

0 comments on commit 5b85875

Please sign in to comment.