Skip to content

Commit

Permalink
fix: fixed how we determine active value for SAP (#1886)
Browse files Browse the repository at this point in the history
  • Loading branch information
sameenfatima78 authored Oct 3, 2023
1 parent f04c9bf commit adb7f83
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Change Log
Unreleased
----------
[4.5.1]
-------
fix: fix how we determine the value of active flag within schedule for SAP

[4.5.0]
-------
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.5.0"
__version__ = "4.5.1"
25 changes: 18 additions & 7 deletions enterprise/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,19 @@ def get_course_run_duration_info(course_run):
return duration_info


def get_advertised_or_closest_course_run(content_metadata_item):
"""
Returns advertised course run of a course. If the advertised run does not exist, it looks for the closest run.
"""
course_run = get_advertised_course_run(content_metadata_item)
# get the closest run if advertised run doesn't exist
if not course_run:
course_runs = content_metadata_item.get('course_runs')
if course_runs:
course_run = get_closest_course_run(course_runs)
return course_run


def get_duration_of_course_or_courserun(content_metadata_item):
"""
Returns duration start, end dates given a piece of content_metadata item
Expand All @@ -1212,12 +1225,10 @@ def get_duration_of_course_or_courserun(content_metadata_item):
start = content_metadata_item.get('start')
end = content_metadata_item.get('end')
elif content_metadata_item.get('content_type') == 'course':
course_runs = content_metadata_item.get('course_runs')
if course_runs:
course_run = get_closest_course_run(course_runs)
if course_run:
start = course_run.get('start')
end = course_run.get('end')
course_run = get_advertised_or_closest_course_run(content_metadata_item)
if course_run:
start = course_run.get('start')
end = course_run.get('end')
if not start:
return 0, None, None
start_date = parse_datetime_handle_invalid(start)
Expand Down Expand Up @@ -1259,7 +1270,7 @@ def is_course_run_available_for_enrollment(course_run):
Check if a course run is available for enrollment.
"""
# If the course run is Archived, it's not available for enrollment
if course_run['availability'] not in ['Current', 'Starting Soon', 'Upcoming']:
if course_run.get('availability') not in ['Current', 'Starting Soon', 'Upcoming']:
return False

# If the course run is not "enrollable", it's not available for enrollment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from enterprise.constants import IC_DELETE_ACTION
from enterprise.utils import (
get_advertised_course_run,
get_advertised_or_closest_course_run,
get_closest_course_run,
get_duration_of_course_or_courserun,
is_course_run_active,
Expand Down Expand Up @@ -169,6 +170,10 @@ def transform_schedule(self, content_metadata_item):
Return the schedule of the content item.
"""
duration, start, end = get_duration_of_course_or_courserun(content_metadata_item)
if content_metadata_item.get('content_type') == 'course':
course_run = get_advertised_or_closest_course_run(content_metadata_item)
if course_run:
content_metadata_item = course_run

# SAP will throw errors if we try to send an empty start or end date
if (not start or not end):
Expand All @@ -177,7 +182,7 @@ def transform_schedule(self, content_metadata_item):
return [{
'startDate': parse_datetime_to_epoch_millis(start) if start else '',
'endDate': parse_datetime_to_epoch_millis(end) if end else '',
'active': current_time_is_in_interval(start, end) if start else False,
'active': is_course_run_available_for_enrollment(content_metadata_item),
'duration': f"{duration} days",
}]

Expand Down

0 comments on commit adb7f83

Please sign in to comment.