Commit 747c28a0 by Peter Fogg

Include courses with no end date in active course runs.

parent a03d7675
...@@ -2,6 +2,7 @@ import datetime ...@@ -2,6 +2,7 @@ import datetime
import pytz import pytz
from django.db import models from django.db import models
from django.db.models.query_utils import Q
class CourseQuerySet(models.QuerySet): class CourseQuerySet(models.QuerySet):
...@@ -9,4 +10,7 @@ class CourseQuerySet(models.QuerySet): ...@@ -9,4 +10,7 @@ class CourseQuerySet(models.QuerySet):
""" Filters Courses to those with CourseRuns that are either currently open for enrollment, """ Filters Courses to those with CourseRuns that are either currently open for enrollment,
or will be open for enrollment in the future. """ or will be open for enrollment in the future. """
return self.filter(course_runs__enrollment_end__gt=datetime.datetime.now(pytz.UTC)) return self.filter(
Q(course_runs__enrollment_end__gt=datetime.datetime.now(pytz.UTC)) |
Q(course_runs__enrollment_end__isnull=True)
)
...@@ -8,6 +8,7 @@ from course_discovery.apps.course_metadata.tests.factories import CourseRunFacto ...@@ -8,6 +8,7 @@ from course_discovery.apps.course_metadata.tests.factories import CourseRunFacto
class CourseQuerySetTests(TestCase): class CourseQuerySetTests(TestCase):
def test_active(self): def test_active(self):
""" Verify the method filters the Courses to those with active course runs. """ """ Verify the method filters the Courses to those with active course runs. """
# Create an active course # Create an active course
...@@ -18,4 +19,7 @@ class CourseQuerySetTests(TestCase): ...@@ -18,4 +19,7 @@ class CourseQuerySetTests(TestCase):
enrollment_end = datetime.datetime.now(pytz.UTC) - datetime.timedelta(days=30) enrollment_end = datetime.datetime.now(pytz.UTC) - datetime.timedelta(days=30)
CourseRunFactory(enrollment_end=enrollment_end, course__title='ABC Test Course 2') CourseRunFactory(enrollment_end=enrollment_end, course__title='ABC Test Course 2')
self.assertListEqual(list(Course.objects.active()), [active_course]) # Create a course with unrestricted enrollment
course_without_end = CourseRunFactory(enrollment_end=None).course
self.assertEqual(set(Course.objects.active()), {active_course, course_without_end})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment