Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added currency field to course run search api #88

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions course_discovery/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,7 @@ class Meta:
class CourseRunSearchSerializer(HaystackSerializer):
availability = serializers.SerializerMethodField()
first_enrollable_paid_seat_price = serializers.SerializerMethodField()
first_enrollable_paid_seat_currency = serializers.SerializerMethodField()
type = serializers.SerializerMethodField()
is_enrollable = serializers.SerializerMethodField()

Expand All @@ -2216,6 +2217,9 @@ def get_availability(self, result):
def get_first_enrollable_paid_seat_price(self, result):
return result.object.first_enrollable_paid_seat_price

def get_first_enrollable_paid_seat_currency(self, result):
return result.object.first_enrollable_paid_seat_currency

def get_type(self, result):
return result.object.type_legacy

Expand All @@ -2234,6 +2238,7 @@ class Meta:
'enrollment_start',
'first_enrollable_paid_seat_sku',
'first_enrollable_paid_seat_price',
'first_enrollable_paid_seat_currency',
'full_description',
'go_live_date',
'has_enrollable_seats',
Expand Down
11 changes: 11 additions & 0 deletions course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,17 @@ def first_enrollable_paid_seat_price(self):

price = int(seats[0].price) if seats[0].price else None
return price

@property
def first_enrollable_paid_seat_currency(self):
"""
Returns currency code for first enrollable paid seat.
"""
seats = sorted(self._enrollable_paid_seats(), key=self._upgrade_deadline_sort)
if not seats:
return None

return seats[0].currency.code or None

def first_enrollable_paid_seat_sku(self):
# Sort in python to avoid an additional request to the database for order_by
Expand Down
4 changes: 4 additions & 0 deletions course_discovery/apps/course_metadata/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class CourseRunIndex(BaseCourseIndex, indexes.Indexable):
has_enrollable_paid_seats = indexes.BooleanField(null=False)
first_enrollable_paid_seat_sku = indexes.CharField(null=True)
first_enrollable_paid_seat_price = indexes.IntegerField(null=True)
first_enrollable_paid_seat_currency = indexes.CharField(null=True)
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)
Expand Down Expand Up @@ -288,6 +289,9 @@ def prepare_first_enrollable_paid_seat_sku(self, obj):
def prepare_first_enrollable_paid_seat_price(self, obj):
return obj.first_enrollable_paid_seat_price

def prepare_first_enrollable_paid_seat_currency(self, obj):
return obj.first_enrollable_paid_seat_currency

def prepare_is_current_and_still_upgradeable(self, obj):
return obj.is_current_and_still_upgradeable()

Expand Down