PR updates

This commit is contained in:
Albert St. Aubin
2018-01-29 12:22:56 -05:00
parent 3876a823f8
commit 12e77b27e4
3 changed files with 11 additions and 9 deletions

View File

@@ -332,11 +332,11 @@ class EntitlementEnrollmentViewSet(viewsets.GenericViewSet):
)
# Verify that the run is fullfillable
if not is_course_run_entitlement_fullfillable(course_run_key, datetime.datetime.now(UTC), entitlement):
if not is_course_run_entitlement_fullfillable(course_run_key, entitlement):
return Response(
status=status.HTTP_400_BAD_REQUEST,
data={
'message': 'The User is unable to enroll in Course Run {course_id} it is not available.'.format(
'message': 'The User is unable to enroll in Course Run {course_id}, it is not available.'.format(
course_id=course_run_id
)
}

View File

@@ -1,8 +1,10 @@
from course_modes.models import CourseMode
from django.utils import timezone
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
def is_course_run_entitlement_fullfillable(course_run_id, compare_date, entitlement):
def is_course_run_entitlement_fullfillable(course_run_id, entitlement, compare_date=timezone.now()):
"""
Checks that the current run meets the following criteria for an entitlement
@@ -16,16 +18,16 @@ def is_course_run_entitlement_fullfillable(course_run_id, compare_date, entitlem
entitlement: The Entitlement that we are checking against.
Returns:
bool: True is the Course Run is fullfillable for the CourseEntitlement.
bool: True if the Course Run is fullfillable for the CourseEntitlement.
"""
course_overview = CourseOverview.get_from_id(course_run_id)
# Only courses that have not ended will be displayed
# Verify that the course is still running
run_start = course_overview.start
run_end = course_overview.end
is_running = run_start and (not run_end or (run_end and (run_end > compare_date)))
# Only courses that can currently be enrolled in will be displayed
# Verify that the course run can currently be enrolled
enrollment_start = course_overview.enrollment_start
enrollment_end = course_overview.enrollment_end
can_enroll = (
@@ -33,7 +35,7 @@ def is_course_run_entitlement_fullfillable(course_run_id, compare_date, entitlem
and (not enrollment_end or enrollment_end > compare_date)
)
# Ensure the course is upgradeable and the mode matches the entitlement's mode.
# Ensure the course run is upgradeable and the mode matches the entitlement's mode
unexpired_paid_modes = [mode.slug for mode in CourseMode.paid_modes_for_course(course_run_id)]
can_upgrade = unexpired_paid_modes and entitlement.mode in unexpired_paid_modes

View File

@@ -321,11 +321,11 @@ def get_fulfillable_course_runs_for_entitlement(entitlement, course_runs):
enrollable_sessions = []
# Only show published course runs that can still be enrolled and upgraded
now = datetime.datetime.now(UTC)
search_time = datetime.datetime.now(UTC)
for course_run in course_runs:
course_id = CourseKey.from_string(course_run.get('key'))
is_enrolled = CourseEnrollment.is_enrolled(entitlement.user, str(course_id))
if is_course_run_entitlement_fullfillable(course_id, now, entitlement) and not is_enrolled:
if is_course_run_entitlement_fullfillable(course_id, entitlement, search_time) and not is_enrolled:
enrollable_sessions.append(course_run)
enrollable_sessions.sort(key=lambda session: session.get('start'))