update schedule start when course start date changes

parent 8b8677a0
...@@ -89,19 +89,17 @@ def update_schedules_on_course_start_changed(sender, updated_course_overview, pr ...@@ -89,19 +89,17 @@ def update_schedules_on_course_start_changed(sender, updated_course_overview, pr
Updates all course schedules if course hasn't started yet and Updates all course schedules if course hasn't started yet and
the updated start date is still in the future. the updated start date is still in the future.
""" """
current_time = timezone.now() upgrade_deadline = _calculate_upgrade_deadline(
if previous_start_date > current_time and updated_course_overview.start > current_time: updated_course_overview.id,
upgrade_deadline = _calculate_upgrade_deadline( content_availability_date=updated_course_overview.start,
updated_course_overview.id, )
content_availability_date=updated_course_overview.start, update_course_schedules.apply_async(
) kwargs=dict(
update_course_schedules.apply_async( course_id=unicode(updated_course_overview.id),
kwargs=dict( new_start_date_str=date.serialize(updated_course_overview.start),
course_id=unicode(updated_course_overview.id), new_upgrade_deadline_str=date.serialize(upgrade_deadline),
new_start_date_str=date.serialize(updated_course_overview.start), ),
new_upgrade_deadline_str=date.serialize(upgrade_deadline), )
),
)
def _calculate_upgrade_deadline(course_id, content_availability_date): def _calculate_upgrade_deadline(course_id, content_availability_date):
......
...@@ -165,7 +165,7 @@ class UpdateScheduleTests(SharedModuleStoreTestCase): ...@@ -165,7 +165,7 @@ class UpdateScheduleTests(SharedModuleStoreTestCase):
course.start = course.start + datetime.timedelta(days=3) # new course start changes to another future date course.start = course.start + datetime.timedelta(days=3) # new course start changes to another future date
self.store.update_item(course, ModuleStoreEnum.UserID.test) self.store.update_item(course, ModuleStoreEnum.UserID.test)
enrollment = CourseEnrollment.objects.get(id=enrollment.id) enrollment = CourseEnrollment.objects.get(id=enrollment.id)
self.assert_schedule_dates(enrollment.schedule, enrollment.created) # start remains unchanged self.assert_schedule_dates(enrollment.schedule, course.start) # start set to new course start
def test_not_updated_since_new_start_in_past(self, mock_get_current_site): def test_not_updated_since_new_start_in_past(self, mock_get_current_site):
mock_get_current_site.return_value = self.site mock_get_current_site.return_value = self.site
...@@ -178,7 +178,7 @@ class UpdateScheduleTests(SharedModuleStoreTestCase): ...@@ -178,7 +178,7 @@ class UpdateScheduleTests(SharedModuleStoreTestCase):
course.start = course.start + datetime.timedelta(days=-10) # new course start changes to a past date course.start = course.start + datetime.timedelta(days=-10) # new course start changes to a past date
self.store.update_item(course, ModuleStoreEnum.UserID.test) self.store.update_item(course, ModuleStoreEnum.UserID.test)
enrollment = CourseEnrollment.objects.get(id=enrollment.id) enrollment = CourseEnrollment.objects.get(id=enrollment.id)
self.assert_schedule_dates(enrollment.schedule, previous_start) # start remains unchanged self.assert_schedule_dates(enrollment.schedule, course.start) # start set to new course start
def _create_course_run(self_paced=True, start_day_offset=-1): def _create_course_run(self_paced=True, start_day_offset=-1):
......
Markdown is supported
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