Skip to content

Commit

Permalink
refactor: and remove duplicate function
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzawaleed01 committed Jan 28, 2025
1 parent 47e49b4 commit ea7d8c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
25 changes: 4 additions & 21 deletions enterprise_catalog/apps/api/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
urlunsplit,
)

from enterprise_catalog.apps.catalog.content_metadata_utils import (
is_course_run_active,
)


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -59,27 +63,6 @@ def get_enterprise_utm_context(enterprise_name):
return utm_context


def is_course_run_active(course_run):
"""
Checks whether a course run is active. That is, whether the course run is published,
enrollable, and marketable.
Arguments:
course_run (dict): The metadata about a course run.
Returns:
bool: True if course run is "active"
"""
is_enrollable = course_run.get('is_enrollable', False)
if course_run.get("is_marketable_external") and is_enrollable:
return True
course_run_status = course_run.get('status') or ''
is_published = course_run_status.lower() == 'published'
is_marketable = course_run.get('is_marketable', False)

return is_published and is_enrollable and is_marketable


def is_any_course_run_active(course_runs):
"""
Iterates over all course runs to check if there any course run that is available for enrollment.
Expand Down
12 changes: 8 additions & 4 deletions enterprise_catalog/apps/catalog/content_metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,23 @@ def is_course_run_active(course_run):
"""
Checks whether a course run is active. That is, whether the course run is published,
enrollable, and marketable.
Checking is_published in case of is_marketable_external is redundant because
the Discovery service already handles the status behind is_marketable_external
property.
Arguments:
course_run (dict): The metadata about a course run.
Returns:
bool: True if course run is "active"
"""
is_enrollable = course_run.get('is_enrollable', False)
if course_run.get("is_marketable_external") and is_enrollable:
return True
course_run_status = course_run.get('status') or ''
is_published = course_run_status.lower() == 'published'
is_marketable = course_run.get('is_marketable', False)
is_enrollable = course_run.get('is_enrollable', False)

is_marketable_internal = is_published and is_marketable
is_marketable_external = course_run.get("is_marketable_external", False)

return is_published and is_enrollable and is_marketable
return is_enrollable and (is_marketable_internal or is_marketable_external)


def get_course_first_paid_enrollable_seat_price(course):
Expand Down

0 comments on commit ea7d8c7

Please sign in to comment.