Skip to content

Commit

Permalink
Merge pull request #1849 from openedx/eahmadjaved/ENT-7496
Browse files Browse the repository at this point in the history
fix: enrolled course card grouping behavior for exec-ed courses
  • Loading branch information
jajjibhai008 committed Aug 23, 2023
2 parents 80e7fef + b4dcfe9 commit 78b43c8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Change Log
Unreleased
----------

[4.0.18]
--------
fix: enrolled course card grouping behavior for exec-ed courses

[4.0.17]
--------
chore: restoring licensed enrollment table if it does not exist
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Your project description goes here.
"""

__version__ = "4.0.17"
__version__ = "4.0.18"

default_app_config = "enterprise.apps.EnterpriseConfig"
1 change: 1 addition & 0 deletions enterprise/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CourseModes:
]

EXEC_ED_COURSE_TYPE = "executive-education-2u"
PRODUCT_SOURCE_2U = "2u"
EXEC_ED_CONTENT_DESCRIPTION_TAG = ("This instructor-led Executive Education course is "
"presented by GetSmarter, an edX partner. ")

Expand Down
11 changes: 10 additions & 1 deletion enterprise_learner_portal/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
from django.conf import settings
from django.utils.translation import gettext as _

from enterprise.constants import EXEC_ED_COURSE_TYPE, PRODUCT_SOURCE_2U
from enterprise.models import EnterpriseCustomerUser
from enterprise.utils import NotConnectedToOpenEdX
from enterprise_learner_portal.utils import get_course_run_status
from enterprise_learner_portal.utils import get_course_run_status, get_exec_ed_course_run_status

try:
from lms.djangoapps.bulk_email.api import get_emails_enabled
Expand Down Expand Up @@ -87,6 +88,14 @@ def to_representation(self, instance):
representation['end_date'] = course_details.end_date or representation['end_date']
representation['enroll_by'] = course_details.enroll_by

if (course_details.product_source == PRODUCT_SOURCE_2U and
course_details.course_type == EXEC_ED_COURSE_TYPE):
representation['course_run_status'] = get_exec_ed_course_run_status(
course_details,
certificate_info,
instance
)

return representation

def _get_course_overview(self, course_run_id):
Expand Down
40 changes: 40 additions & 0 deletions enterprise_learner_portal/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""
enterprise_learner_portal utils.
"""
from datetime import datetime

from pytz import utc


class CourseRunProgressStatuses:
Expand Down Expand Up @@ -44,3 +47,40 @@ def get_course_run_status(course_overview, certificate_info, enterprise_enrollme
if course_overview['has_started']:
return CourseRunProgressStatuses.IN_PROGRESS
return CourseRunProgressStatuses.UPCOMING


def get_exec_ed_course_run_status(course_details, certificate_info, enterprise_enrollment):
"""
Get the status of a exec ed course run, given the state of a user's certificate in the course.
A run is considered "complete" when either the course run has ended OR the user has earned a
passing certificate.
Arguments:
course_details : the details for the exececutive education course run
certificate_info: A dict containing the following key:
``is_passing``: whether the user has a passing certificate in the course run
Returns:
status: one of (
CourseRunProgressStatuses.SAVED_FOR_LATER,
CourseRunProgressStatuses.COMPLETE,
CourseRunProgressStatuses.IN_PROGRESS,
CourseRunProgressStatuses.UPCOMING,
)
"""
if enterprise_enrollment and enterprise_enrollment.saved_for_later:
return CourseRunProgressStatuses.SAVED_FOR_LATER

is_certificate_passing = certificate_info.get('is_passing', False)
start_date = course_details.start_date
end_date = course_details.end_date

has_started = datetime.now(utc) > start_date if start_date is not None else True
has_ended = datetime.now(utc) > end_date if end_date is not None else False

if has_ended or is_certificate_passing:
return CourseRunProgressStatuses.COMPLETED
if has_started:
return CourseRunProgressStatuses.IN_PROGRESS
return CourseRunProgressStatuses.UPCOMING

0 comments on commit 78b43c8

Please sign in to comment.