Merge pull request #25988 from edx/AA-488

[AA-488] Remove uses of the active field on the schedule model in the code.
This commit is contained in:
Matthew Piatetsky
2021-01-11 09:34:00 -05:00
committed by GitHub
5 changed files with 6 additions and 34 deletions

View File

@@ -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(

View File

@@ -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()

View File

@@ -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')

View File

@@ -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,

View File

@@ -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
"""