Skip to content
Snippets Groups Projects
Unverified Commit 84930bd5 authored by Dillon Dumesnil's avatar Dillon Dumesnil Committed by GitHub
Browse files

Merge pull request #25721 from edx/ddumesnil/aa-454

AA-454: Reenable CourseUpdateResolver for Instructor-paced Courses
parents 0e6d08cb ef5832bc
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ from openedx.core.djangoapps.schedules.tasks import ScheduleCourseNextSectionUpd ...@@ -14,7 +14,7 @@ from openedx.core.djangoapps.schedules.tasks import ScheduleCourseNextSectionUpd
class Command(SendEmailBaseCommand): class Command(SendEmailBaseCommand):
""" """
Command to send Schedule course updates Command to send Schedule course updates for Self-paced Courses
""" """
help = dedent(__doc__).strip() help = dedent(__doc__).strip()
async_send_task = ScheduleCourseNextSectionUpdate async_send_task = ScheduleCourseNextSectionUpdate
......
...@@ -12,7 +12,7 @@ from openedx.core.djangoapps.schedules.tasks import ScheduleCourseUpdate ...@@ -12,7 +12,7 @@ from openedx.core.djangoapps.schedules.tasks import ScheduleCourseUpdate
class Command(SendEmailBaseCommand): class Command(SendEmailBaseCommand):
""" """
Command to send Schedule course updates Command to send Schedule course updates for Instructor-paced Courses
""" """
help = dedent(__doc__).strip() help = dedent(__doc__).strip()
async_send_task = ScheduleCourseUpdate async_send_task = ScheduleCourseUpdate
......
...@@ -352,6 +352,8 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver): ...@@ -352,6 +352,8 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver):
""" """
Send a message to all users whose schedule started at ``self.current_date`` + ``day_offset`` and the Send a message to all users whose schedule started at ``self.current_date`` + ``day_offset`` and the
course has updates. course has updates.
Only used for Instructor-paced Courses
""" """
log_prefix = 'Course Update' log_prefix = 'Course Update'
schedule_date_field = 'start_date' schedule_date_field = 'start_date'
...@@ -359,9 +361,8 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver): ...@@ -359,9 +361,8 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver):
experience_filter = Q(experience__experience_type=ScheduleExperience.EXPERIENCES.course_updates) experience_filter = Q(experience__experience_type=ScheduleExperience.EXPERIENCES.course_updates)
def send(self, msg_type): def send(self, msg_type):
for (user, language, context, is_self_paced) in self.schedules_for_bin(): for (user, language, context) in self.schedules_for_bin():
msg_type = CourseUpdate() if is_self_paced else InstructorLedCourseUpdate() msg = InstructorLedCourseUpdate().personalize(
msg = msg_type.personalize(
Recipient( Recipient(
user.username, user.username,
self.override_recipient_email or user.email, self.override_recipient_email or user.email,
...@@ -384,6 +385,11 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver): ...@@ -384,6 +385,11 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver):
course = schedule.enrollment.course course = schedule.enrollment.course
user = enrollment.user user = enrollment.user
# (Weekly) Course Updates are only for Instructor-paced courses.
# See CourseNextSectionUpdate for Self-paced updates.
if course.self_paced:
continue
try: try:
week_highlights = get_week_highlights(user, enrollment.course_id, week_num) week_highlights = get_week_highlights(user, enrollment.course_id, week_num)
except CourseUpdateDoesNotExist: except CourseUpdateDoesNotExist:
...@@ -415,13 +421,15 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver): ...@@ -415,13 +421,15 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver):
}) })
template_context.update(_get_upsell_information_for_schedule(user, schedule)) 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 @attr.s
class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver): class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver):
""" """
Send a message to all users whose schedule gives them a due date of yesterday. 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() async_send_task = attr.ib()
site = attr.ib() site = attr.ib()
...@@ -434,9 +442,8 @@ class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver): ...@@ -434,9 +442,8 @@ class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver):
def send(self): def send(self):
schedules = self.get_schedules() schedules = self.get_schedules()
for (user, language, context, is_self_paced) in schedules: for (user, language, context) in schedules:
msg_type = CourseUpdate() if is_self_paced else InstructorLedCourseUpdate() msg = CourseUpdate().personalize(
msg = msg_type.personalize(
Recipient( Recipient(
user.username, user.username,
self.override_recipient_email or user.email, self.override_recipient_email or user.email,
...@@ -477,6 +484,11 @@ class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver): ...@@ -477,6 +484,11 @@ class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver):
if course.end and course.end.date() <= target_date: if course.end and course.end.date() <= target_date:
return 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 user = schedule.enrollment.user
start_date = max(filter(None, (schedule.start_date, course.start))) start_date = max(filter(None, (schedule.start_date, course.start)))
LOG.info('Received a schedule for user {} in course {} for date {}'.format( LOG.info('Received a schedule for user {} in course {} for date {}'.format(
...@@ -512,7 +524,7 @@ class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver): ...@@ -512,7 +524,7 @@ class CourseNextSectionUpdate(PrefixedDebugLoggerMixin, RecipientResolver):
}) })
template_context.update(_get_upsell_information_for_schedule(user, schedule)) 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): def _get_trackable_course_home_url(course_id):
......
...@@ -103,7 +103,7 @@ class TestCourseUpdateResolver(SchedulesResolverTestMixin, ModuleStoreTestCase): ...@@ -103,7 +103,7 @@ class TestCourseUpdateResolver(SchedulesResolverTestMixin, ModuleStoreTestCase):
""" """
def setUp(self): def setUp(self):
super().setUp() 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): with self.store.bulk_operations(self.course.id):
ItemFactory.create(parent=self.course, category='chapter', highlights=['good stuff']) ItemFactory.create(parent=self.course, category='chapter', highlights=['good stuff'])
...@@ -147,7 +147,7 @@ class TestCourseUpdateResolver(SchedulesResolverTestMixin, ModuleStoreTestCase): ...@@ -147,7 +147,7 @@ class TestCourseUpdateResolver(SchedulesResolverTestMixin, ModuleStoreTestCase):
'week_highlights': ['good stuff'], 'week_highlights': ['good stuff'],
'week_num': 1, '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_waffle_flag(COURSE_UPDATE_WAFFLE_FLAG, True)
@override_switch('schedules.course_update_show_unsubscribe', True) @override_switch('schedules.course_update_show_unsubscribe', True)
...@@ -240,7 +240,7 @@ class TestCourseNextSectionUpdateResolver(SchedulesResolverTestMixin, ModuleStor ...@@ -240,7 +240,7 @@ class TestCourseNextSectionUpdateResolver(SchedulesResolverTestMixin, ModuleStor
'week_highlights': ['good stuff 2'], 'week_highlights': ['good stuff 2'],
'week_num': 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_waffle_flag(COURSE_UPDATE_WAFFLE_FLAG, True)
@override_switch('schedules.course_update_show_unsubscribe', True) @override_switch('schedules.course_update_show_unsubscribe', True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment