Merge pull request #17008 from edx/HarryRein/entitlements-without-sessions
Show more sessions coming soon for entitlements without sessions.
This commit is contained in:
@@ -1,33 +1,39 @@
|
||||
<div id="change-session-<%- entitlementUUID %>" class="message is-shown">
|
||||
<div class="action-header">
|
||||
<% if (currentSessionId) { %>
|
||||
<%- gettext('Change to a different session or leave the current session.')%>
|
||||
<% if (availableSessions.length === 0) { %>
|
||||
<%- gettext('More sessions coming soon.') %>
|
||||
<% } else { %>
|
||||
<%- gettext('To access the course, select a session.')%>
|
||||
<% if (currentSessionId) { %>
|
||||
<%- gettext('Change to a different session or leave the current session.')%>
|
||||
<% } else { %>
|
||||
<%- gettext('To access the course, select a session.')%>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</div>
|
||||
<div class="action-controls">
|
||||
<select class="session-select" aria-label="<%- StringUtils.interpolate( gettext('Session Selection Dropdown for {courseName}'), { courseName: courseName }) %>">
|
||||
<% _.each(availableSessions, function(session) { %>
|
||||
<option data-session_id="<%- session.session_id || session.key %>">
|
||||
<% if ((session.session_id || session.key) === currentSessionId) { %>
|
||||
<%- StringUtils.interpolate( gettext('{sessionDates} - Currently Selected'), {sessionDates: session.session_dates}) %>
|
||||
<% } else if (session.enrollment_end){ %>
|
||||
<%- StringUtils.interpolate( gettext('{sessionDates} (Open until {enrollmentEnd})'), {sessionDates: session.session_dates, enrollmentEnd: session.enrollment_end}) %>
|
||||
<% } else { %>
|
||||
<%- session.session_dates %>
|
||||
<% } %>
|
||||
</option>
|
||||
<% }) %>
|
||||
<option disabled><%- gettext('More sessions coming soon') %></option>
|
||||
<% if (currentSessionId){%> <option><%- gettext('Leave the current session and decide later')%></option><% } %>
|
||||
</select>
|
||||
<button class="enroll-btn-initial">
|
||||
<% if (currentSessionId) { %>
|
||||
<%- gettext('Change Session') %>
|
||||
<% } else { %>
|
||||
<%- gettext('Select Session') %>
|
||||
<% } %>
|
||||
</button>
|
||||
</div>
|
||||
<% if (availableSessions.length !== 0) { %>
|
||||
<div class="action-controls">
|
||||
<select class="session-select" aria-label="<%- StringUtils.interpolate( gettext('Session Selection Dropdown for {courseName}'), { courseName: courseName }) %>">
|
||||
<% _.each(availableSessions, function(session) { %>
|
||||
<option data-session_id="<%- session.session_id || session.key %>">
|
||||
<% if ((session.session_id || session.key) === currentSessionId) { %>
|
||||
<%- StringUtils.interpolate( gettext('{sessionDates} - Currently Selected'), {sessionDates: session.session_dates}) %>
|
||||
<% } else if (session.enrollment_end){ %>
|
||||
<%- StringUtils.interpolate( gettext('{sessionDates} (Open until {enrollmentEnd})'), {sessionDates: session.session_dates, enrollmentEnd: session.enrollment_end}) %>
|
||||
<% } else { %>
|
||||
<%- session.session_dates %>
|
||||
<% } %>
|
||||
</option>
|
||||
<% }) %>
|
||||
<option disabled><%- gettext('More sessions coming soon') %></option>
|
||||
<% if (currentSessionId){%> <option><%- gettext('Leave the current session and decide later')%></option><% } %>
|
||||
</select>
|
||||
<button class="enroll-btn-initial">
|
||||
<% if (currentSessionId) { %>
|
||||
<%- gettext('Change Session') %>
|
||||
<% } else { %>
|
||||
<%- gettext('Select Session') %>
|
||||
<% } %>
|
||||
</button>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
@@ -245,19 +245,28 @@ def get_course_runs_for_course(course_uuid):
|
||||
|
||||
def get_visible_course_runs_for_entitlement(entitlement):
|
||||
"""
|
||||
We only want to show courses for a particular entitlement that:
|
||||
Returns only the course runs that the user can currently enroll in.
|
||||
"""
|
||||
sessions_for_course = get_course_runs_for_course(entitlement.course_uuid)
|
||||
return get_fulfillable_course_runs_for_entitlement(entitlement, sessions_for_course)
|
||||
|
||||
|
||||
def get_fulfillable_course_runs_for_entitlement(entitlement, course_runs):
|
||||
"""
|
||||
Takes a list of course runs and returns only the course runs that:
|
||||
|
||||
1) Are currently running or in the future
|
||||
2) A user can enroll in
|
||||
3) A user can upgrade in
|
||||
4) Are published
|
||||
|
||||
These are the only sessions that can be selected for an entitlement.
|
||||
"""
|
||||
sessions_for_course = get_course_runs_for_course(entitlement.course_uuid)
|
||||
enrollable_sessions = []
|
||||
|
||||
# Only show published course runs that can still be enrolled and upgraded
|
||||
now = datetime.datetime.now(UTC)
|
||||
for course_run in sessions_for_course:
|
||||
for course_run in course_runs:
|
||||
# Only courses that have not ended will be displayed
|
||||
run_start = course_run.get('start')
|
||||
run_end = course_run.get('end')
|
||||
|
||||
@@ -24,7 +24,7 @@ from lms.djangoapps.certificates import api as certificate_api
|
||||
from lms.djangoapps.commerce.utils import EcommerceService
|
||||
from lms.djangoapps.courseware.access import has_access
|
||||
from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory
|
||||
from openedx.core.djangoapps.catalog.utils import get_programs
|
||||
from openedx.core.djangoapps.catalog.utils import get_programs, get_fulfillable_course_runs_for_entitlement
|
||||
from openedx.core.djangoapps.commerce.utils import ecommerce_api_client
|
||||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
||||
from openedx.core.djangoapps.credentials.utils import get_credentials
|
||||
@@ -230,6 +230,7 @@ class ProgramProgressMeter(object):
|
||||
elif self._is_course_enrolled(course) or active_entitlement:
|
||||
# Show all currently enrolled courses and active entitlements as in progress
|
||||
if active_entitlement:
|
||||
course['course_runs'] = get_fulfillable_course_runs_for_entitlement(active_entitlement, course['course_runs'])
|
||||
course['user_entitlement'] = active_entitlement.to_dict()
|
||||
course['enroll_url'] = reverse(
|
||||
'entitlements_api:v1:enrollments',
|
||||
|
||||
Reference in New Issue
Block a user