diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index eff31878a5..2c58927ee9 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -1966,7 +1966,7 @@ class CourseEnrollment(models.Model): return None try: - if not self.schedule or not self.schedule.active: # pylint: disable=no-member + if not self.schedule or not self.schedule.enrollment.is_active: # pylint: disable=no-member return None log.debug( diff --git a/openedx/core/djangoapps/schedules/admin.py b/openedx/core/djangoapps/schedules/admin.py index 0355f05744..a2b3d12d13 100644 --- a/openedx/core/djangoapps/schedules/admin.py +++ b/openedx/core/djangoapps/schedules/admin.py @@ -122,29 +122,18 @@ class CourseIdFilter(admin.SimpleListFilter): @admin.register(models.Schedule) class ScheduleAdmin(admin.ModelAdmin): - list_display = ('username', 'course_id', 'active', 'start_date', 'upgrade_deadline', 'experience_display') + list_display = ('username', 'course_id', 'start_date', 'upgrade_deadline', 'experience_display') list_display_links = ('start_date', 'upgrade_deadline', 'experience_display') list_filter = ( CourseIdFilter, 'experience__experience_type', - 'active', KnownErrorCases ) raw_id_fields = ('enrollment',) readonly_fields = ('modified',) search_fields = ('enrollment__user__username',) inlines = (ScheduleExperienceAdminInline,) - actions = ['deactivate_schedules', 'activate_schedules'] + experience_actions - - def deactivate_schedules(self, request, queryset): - rows_updated = queryset.update(active=False) - self.message_user(request, u"{} schedule(s) were deactivated".format(rows_updated)) - deactivate_schedules.short_description = "Deactivate selected schedules" - - def activate_schedules(self, request, queryset): - rows_updated = queryset.update(active=True) - self.message_user(request, u"{} schedule(s) were activated".format(rows_updated)) - activate_schedules.short_description = "Activate selected schedules" + actions = experience_actions def experience_display(self, obj): return obj.experience.get_experience_type_display() diff --git a/openedx/core/djangoapps/schedules/models.py b/openedx/core/djangoapps/schedules/models.py index a3792eb554..7efbaf10fa 100644 --- a/openedx/core/djangoapps/schedules/models.py +++ b/openedx/core/djangoapps/schedules/models.py @@ -15,6 +15,9 @@ class Schedule(TimeStampedModel): """ enrollment = models.OneToOneField('student.CourseEnrollment', null=False, on_delete=models.CASCADE) + # The active field on the schedule is deprecated, please do not rely on it. + # You can use the is_active field on the CourseEnrollment model instead (i.e. schedule.enrollment.is_active). + # Removing this field from the database is a TODO for https://openedx.atlassian.net/browse/AA-574. active = models.BooleanField( default=True, help_text=_('Indicates if this schedule is actively used') diff --git a/openedx/core/djangoapps/schedules/resolvers.py b/openedx/core/djangoapps/schedules/resolvers.py index 839a5b7298..1d87b29733 100644 --- a/openedx/core/djangoapps/schedules/resolvers.py +++ b/openedx/core/djangoapps/schedules/resolvers.py @@ -141,7 +141,6 @@ class BinnedSchedulesBaseResolver(PrefixedDebugLoggerMixin, RecipientResolver): self.experience_filter, enrollment__user__in=users, enrollment__is_active=True, - active=True, **schedule_day_equals_target_day_filter ).order_by(order_by) @@ -470,7 +469,6 @@ class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver): course_duration = get_expected_duration(self.course_id) schedules = Schedule.objects.select_related('enrollment').filter( self.experience_filter, - active=True, enrollment__is_active=True, enrollment__course_id=self.course_id, enrollment__user__is_active=True, diff --git a/openedx/core/djangoapps/schedules/signals.py b/openedx/core/djangoapps/schedules/signals.py index c5a7ca6af4..fb75409420 100644 --- a/openedx/core/djangoapps/schedules/signals.py +++ b/openedx/core/djangoapps/schedules/signals.py @@ -61,24 +61,6 @@ def create_schedule(sender, **kwargs): # pylint: disable=unused-argument )) -@receiver(ENROLL_STATUS_CHANGE) -def update_schedule(sender, event, user, course_id, **kwargs): # pylint: disable=unused-argument - """ - When a CourseEnrollment's status is updated, update the Schedule's active status if configured. - """ - try: - schedule = Schedule.objects.get(enrollment__user=user, enrollment__course=course_id) - except Schedule.DoesNotExist: - # Exit since it could just be an indication of Schedules are not enabled. - return - - if event == 'enroll': - schedule.active = True - elif event == 'unenroll': - schedule.active = False - schedule.save() - - @receiver(COURSE_START_DATE_CHANGED) def update_schedules_on_course_start_changed(sender, updated_course_overview, previous_start_date, **kwargs): # pylint: disable=unused-argument """