def _get_upgrade_deadline_delta_setting(course_id): delta = None global_config = DynamicUpgradeDeadlineConfiguration.current() if global_config.enabled: # Use the default from this model whether or not the feature is enabled delta = global_config.deadline_days # Check if the course has a deadline course_config = CourseDynamicUpgradeDeadlineConfiguration.current(course_id) if course_config.enabled: delta = course_config.deadline_days return delta
def _get_upgrade_deadline(enrollment): """ Returns the upgrade deadline for the given enrollment. The deadline is determined based on the following data (in priority order): 1. Course run-specific deadline configuration (CourseDynamicUpgradeDeadlineConfiguration) 2. Global deadline configuration (DynamicUpgradeDeadlineConfiguration) 3. Verified course mode expiration """ course_key = enrollment.course_id upgrade_deadline = None try: verified_mode = CourseMode.verified_mode_for_course(course_key) if verified_mode: upgrade_deadline = verified_mode.expiration_datetime except CourseMode.DoesNotExist: pass global_config = DynamicUpgradeDeadlineConfiguration.current() if global_config.enabled: delta = global_config.deadline_days # Check if the given course has opted out of the feature course_config = CourseDynamicUpgradeDeadlineConfiguration.current( course_key) if course_config.enabled: if course_config.opt_out: return upgrade_deadline delta = course_config.deadline_days course_overview = CourseOverview.get_from_id(course_key) # This represents the first date at which the learner can access the content. This will be the latter of # either the enrollment date or the course's start date. content_availability_date = max(enrollment.created, course_overview.start) cav_based_deadline = content_availability_date + datetime.timedelta( days=delta) # If the deadline from above is None, make sure we have a value for comparison upgrade_deadline = upgrade_deadline or datetime.date.max # The content availability-based deadline should never occur after the verified mode's # expiration date, if one is set. upgrade_deadline = min(upgrade_deadline, cav_based_deadline) return upgrade_deadline
def date(self): deadline = None try: verified_mode = CourseMode.objects.get( course_id=self.course_id, mode_slug=CourseMode.VERIFIED) deadline = verified_mode.expiration_datetime except CourseMode.DoesNotExist: pass if self.course and self.course_overview.self_paced and self.enrollment: global_config = DynamicUpgradeDeadlineConfiguration.current() if global_config.enabled: delta = global_config.deadline_days # Check if the given course has opted out of the feature course_config = CourseDynamicUpgradeDeadlineConfiguration.current( self.course.id) if course_config.enabled: if course_config.opt_out: return deadline delta = course_config.deadline_days # This represents the first date at which the learner can access the content. This will be the # latter of either the enrollment date or the course's start date. content_availability_date = max(self.enrollment.created, self.course_overview.start) user_deadline = content_availability_date + datetime.timedelta( days=delta) # If the deadline from above is None, make sure we have a value for comparison deadline = deadline or datetime.date.max # The user-specific deadline should never occur after the verified mode's expiration date, # if one is set. deadline = min(deadline, user_deadline) return deadline
def create_schedule(sender, **kwargs): if not kwargs['created']: # only create schedules when enrollment records are created return current_site = get_current_site() if current_site is None: log.debug('Schedules: No current site') return enrollment = kwargs['instance'] schedule_config = ScheduleConfig.current(current_site) if (not schedule_config.create_schedules and not SCHEDULE_WAFFLE_FLAG.is_enabled(enrollment.course_id)): log.debug( 'Schedules: Creation not enabled for this course or for this site') return delta = None if enrollment.course_overview.self_paced: global_config = DynamicUpgradeDeadlineConfiguration.current() if global_config.enabled: # Use the default from this model whether or not the feature is enabled delta = global_config.deadline_days # Check if the course has a deadline override course_config = CourseDynamicUpgradeDeadlineConfiguration.current( enrollment.course_id) if course_config.enabled: delta = course_config.deadline_days upgrade_deadline = None # This represents the first date at which the learner can access the content. This will be the latter of # either the enrollment date or the course's start date. content_availability_date = max(enrollment.created, enrollment.course_overview.start) if delta is not None: upgrade_deadline = content_availability_date + datetime.timedelta( days=delta) course_upgrade_deadline = None try: verified_mode = CourseMode.verified_mode_for_course( enrollment.course_id) except CourseMode.DoesNotExist: pass else: if verified_mode: course_upgrade_deadline = verified_mode.expiration_datetime if course_upgrade_deadline is not None and upgrade_deadline is not None: # The content availability-based deadline should never occur after the verified mode's # expiration date, if one is set. upgrade_deadline = min(upgrade_deadline, course_upgrade_deadline) Schedule.objects.create(enrollment=enrollment, start=content_availability_date, upgrade_deadline=upgrade_deadline) log.debug( 'Schedules: created a new schedule starting at %s with an upgrade deadline of %s', content_availability_date, upgrade_deadline)