Skip to content
Snippets Groups Projects
Commit 287acf5e authored by Matthew Piatetsky's avatar Matthew Piatetsky
Browse files

Add clarifying information regarding user course expiration

parent c4cea14e
No related merge requests found
...@@ -46,14 +46,12 @@ class AuditExpiredError(AccessError): ...@@ -46,14 +46,12 @@ class AuditExpiredError(AccessError):
def get_user_course_expiration_date(user, course): def get_user_course_expiration_date(user, course):
""" """
Return course expiration date for given user course pair. Return expiration date for given user course pair.
Return None if the course does not expire. Return None if the course does not expire.
Defaults to MIN_DURATION.
Business Logic: Business Logic:
- - Course access duration is bounded by the min and max duration.
- should be bounded with min / max - If course fields are missing, default course access duration to MIN_DURATION.
- if fields are missing, default to minimum time
""" """
access_duration = MIN_DURATION access_duration = MIN_DURATION
...@@ -64,23 +62,28 @@ def get_user_course_expiration_date(user, course): ...@@ -64,23 +62,28 @@ def get_user_course_expiration_date(user, course):
return None return None
try: try:
start_date = enrollment.schedule.start # Content availability date is equivalent to max(enrollment date, course start date)
# for most people. Using the schedule date will provide flexibility to deal with
# more complex business rules in the future.
content_availability_date = enrollment.schedule.start
except CourseEnrollment.schedule.RelatedObjectDoesNotExist: except CourseEnrollment.schedule.RelatedObjectDoesNotExist:
start_date = max(enrollment.created, course.start) content_availability_date = max(enrollment.created, course.start)
if course.self_paced: if course.self_paced:
# self-paced expirations should be start date plus the marketing course length discovery # The user course expiration date for self paced courses is the
# content availability date plus the weeks_to_complete field from course-discovery.
discovery_course_details = get_course_run_details(course.id, ['weeks_to_complete']) discovery_course_details = get_course_run_details(course.id, ['weeks_to_complete'])
expected_weeks = discovery_course_details['weeks_to_complete'] or int(MIN_DURATION.days / 7) expected_weeks = discovery_course_details['weeks_to_complete'] or int(MIN_DURATION.days / 7)
access_duration = timedelta(weeks=expected_weeks) access_duration = timedelta(weeks=expected_weeks)
elif not course.self_paced and course.end and course.start: elif not course.self_paced and course.end and course.start:
# instructor-paced expirations should be the start date plus the length of the course # The user course expiration date for instructor paced courses is the
# content availability date plus the duration of the course (course end date minus course start date).
access_duration = course.end - course.start access_duration = course.end - course.start
# available course time should bound my the min and max duration # Course access duration is bounded by the min and max duration.
access_duration = max(MIN_DURATION, min(MAX_DURATION, access_duration)) access_duration = max(MIN_DURATION, min(MAX_DURATION, access_duration))
return start_date + access_duration return content_availability_date + access_duration
def check_course_expired(user, course): def check_course_expired(user, course):
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment