Commit 29a65f26 by Douglas Hall

Add indexed has_enrollable_seats field to CourseRun model.

This field will make it possible for clients of the search/all
endpoint to filter CourseRun results to those that have enrollable
seats.

ENT-687
parent fa67db19
......@@ -56,7 +56,7 @@ COURSE_RUN_SEARCH_FIELDS = (
'enrollment_end', 'pacing_type', 'language', 'transcript_languages', 'marketing_url', 'content_type', 'org',
'number', 'seat_types', 'image_url', 'type', 'level_type', 'availability', 'published', 'partner', 'program_types',
'authoring_organization_uuids', 'subject_uuids', 'staff_uuids', 'mobile_available', 'logo_image_urls',
'aggregation_key', 'min_effort', 'max_effort', 'weeks_to_complete',
'aggregation_key', 'min_effort', 'max_effort', 'weeks_to_complete', 'has_enrollable_seats',
)
PROGRAM_FACET_FIELD_OPTIONS = {
......
......@@ -495,6 +495,14 @@ class CourseRun(TimeStampedModel):
return deadline
@cached_property
def has_enrollable_seats(self):
"""
Return a boolean indicating whether or not enrollable Seats are available for this CourseRun.
"""
seat_types = [choice[0] for choice in Seat.SEAT_TYPE_CHOICES]
return len(self.enrollable_seats(seat_types)[:1]) > 0
def enrollable_seats(self, types):
"""
Returns seats, of the given type(s), that can be enrolled in/purchased.
......
......@@ -170,6 +170,7 @@ class CourseRunIndex(BaseCourseIndex, indexes.Indexable):
has_enrollable_paid_seats = indexes.BooleanField(null=False)
paid_seat_enrollment_end = indexes.DateTimeField(null=True)
license = indexes.MultiValueField(model_attr='license', faceted=True)
has_enrollable_seats = indexes.BooleanField(model_attr='has_enrollable_seats', null=False)
def prepare_aggregation_key(self, obj):
# Aggregate CourseRuns by Course key since that is how we plan to dedup CourseRuns on the marketing site.
......
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