diff --git a/openedx/core/djangoapps/schedules/management/commands/send_course_next_section_update.py b/openedx/core/djangoapps/schedules/management/commands/send_course_next_section_update.py index 8805ebbcaf9b7a1815b51e2b2221731ef87dfb0c..7d117640d4e7cd0a1e214a556538d91d2cc9d1a5 100644 --- a/openedx/core/djangoapps/schedules/management/commands/send_course_next_section_update.py +++ b/openedx/core/djangoapps/schedules/management/commands/send_course_next_section_update.py @@ -14,7 +14,7 @@ from openedx.core.djangoapps.schedules.tasks import ScheduleCourseNextSectionUpd class Command(SendEmailBaseCommand): """ - Command to send Schedule course updates + Command to send Schedule course updates for Self-paced Courses """ help = dedent(__doc__).strip() async_send_task = ScheduleCourseNextSectionUpdate diff --git a/openedx/core/djangoapps/schedules/management/commands/send_course_update.py b/openedx/core/djangoapps/schedules/management/commands/send_course_update.py index 43225caefda65ab2ba45757af3cf78bda55fa285..e15f53178755cb3afc4565947029ffb9d0c3dea5 100644 --- a/openedx/core/djangoapps/schedules/management/commands/send_course_update.py +++ b/openedx/core/djangoapps/schedules/management/commands/send_course_update.py @@ -12,7 +12,7 @@ from openedx.core.djangoapps.schedules.tasks import ScheduleCourseUpdate class Command(SendEmailBaseCommand): """ - Command to send Schedule course updates + Command to send Schedule course updates for Instructor-paced Courses """ help = dedent(__doc__).strip() async_send_task = ScheduleCourseUpdate diff --git a/openedx/core/djangoapps/schedules/resolvers.py b/openedx/core/djangoapps/schedules/resolvers.py index 06b40a855b5e31fa402099b6d2c8aedfb41eb25a..79c80d9e6e00ee98d7646b72b61645dadde2ee60 100644 --- a/openedx/core/djangoapps/schedules/resolvers.py +++ b/openedx/core/djangoapps/schedules/resolvers.py @@ -352,6 +352,8 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver): """ Send a message to all users whose schedule started at ``self.current_date`` + ``day_offset`` and the course has updates. + + Only used for Instructor-paced Courses """ log_prefix = 'Course Update' schedule_date_field = 'start_date' @@ -359,9 +361,8 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver): experience_filter = Q(experience__experience_type=ScheduleExperience.EXPERIENCES.course_updates) def send(self, msg_type): - for (user, language, context, is_self_paced) in self.schedules_for_bin(): - msg_type = CourseUpdate() if is_self_paced else InstructorLedCourseUpdate() - msg = msg_type.personalize( + for (user, language, context) in self.schedules_for_bin(): + msg = InstructorLedCourseUpdate().personalize( Recipient( user.username, self.override_recipient_email or user.email, @@ -384,6 +385,11 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver): course = schedule.enrollment.course user = enrollment.user + # (Weekly) Course Updates are only for Instructor-paced courses. + # See CourseNextSectionUpdate for Self-paced updates. + if course.self_paced: + continue + try: week_highlights = get_week_highlights(user, enrollment.course_id, week_num) except CourseUpdateDoesNotExist: @@ -415,13 +421,15 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver): }) template_context.update(_get_upsell_information_for_schedule(user, schedule)) - yield (user, schedule.enrollment.course.closest_released_language, template_context, course.self_paced) + yield (user, schedule.enrollment.course.closest_released_language, template_context) @attr.s class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver): """ Send a message to all users whose schedule gives them a due date of yesterday. + + Only used for Self-paced Courses """ async_send_task = attr.ib() site = attr.ib() @@ -434,9 +442,8 @@ class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver): def send(self): schedules = self.get_schedules() - for (user, language, context, is_self_paced) in schedules: - msg_type = CourseUpdate() if is_self_paced else InstructorLedCourseUpdate() - msg = msg_type.personalize( + for (user, language, context) in schedules: + msg = CourseUpdate().personalize( Recipient( user.username, self.override_recipient_email or user.email, @@ -477,6 +484,11 @@ class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver): if course.end and course.end.date() <= target_date: return + # Next Section Updates are only for Self-paced courses since it uses Personalized + # Learner Schedule logic. See CourseUpdateResolver for Instructor-paced updates + if not course.self_paced: + continue + user = schedule.enrollment.user start_date = max(filter(None, (schedule.start_date, course.start))) LOG.info('Received a schedule for user {} in course {} for date {}'.format( @@ -512,7 +524,7 @@ class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver): }) template_context.update(_get_upsell_information_for_schedule(user, schedule)) - yield (user, course.closest_released_language, template_context, course.self_paced) + yield (user, course.closest_released_language, template_context) def _get_trackable_course_home_url(course_id): diff --git a/openedx/core/djangoapps/schedules/tests/test_resolvers.py b/openedx/core/djangoapps/schedules/tests/test_resolvers.py index d01d2f3e951667af6a4efb12c6b63c1c11489dd2..873896651ce9e71824f4d2a6300d996c58ae7719 100644 --- a/openedx/core/djangoapps/schedules/tests/test_resolvers.py +++ b/openedx/core/djangoapps/schedules/tests/test_resolvers.py @@ -103,7 +103,7 @@ class TestCourseUpdateResolver(SchedulesResolverTestMixin, ModuleStoreTestCase): """ def setUp(self): super().setUp() - self.course = CourseFactory.create(highlights_enabled_for_messaging=True, self_paced=True) + self.course = CourseFactory.create(highlights_enabled_for_messaging=True) with self.store.bulk_operations(self.course.id): ItemFactory.create(parent=self.course, category='chapter', highlights=['good stuff']) @@ -147,7 +147,7 @@ class TestCourseUpdateResolver(SchedulesResolverTestMixin, ModuleStoreTestCase): 'week_highlights': ['good stuff'], 'week_num': 1, } - self.assertEqual(schedules, [(self.user, None, expected_context, True)]) + self.assertEqual(schedules, [(self.user, None, expected_context)]) @override_waffle_flag(COURSE_UPDATE_WAFFLE_FLAG, True) @override_switch('schedules.course_update_show_unsubscribe', True) @@ -240,7 +240,7 @@ class TestCourseNextSectionUpdateResolver(SchedulesResolverTestMixin, ModuleStor 'week_highlights': ['good stuff 2'], 'week_num': 2, } - self.assertEqual(schedules, [(self.user, None, expected_context, True)]) + self.assertEqual(schedules, [(self.user, None, expected_context)]) @override_waffle_flag(COURSE_UPDATE_WAFFLE_FLAG, True) @override_switch('schedules.course_update_show_unsubscribe', True)