Пример #1
0
 def test_get_schedules_with_due_date_for_abs_date(self):
     self.schedule.start_date = datetime(2019, 3, 22)
     items = make_items(with_relative=False)
     assignment_date = items[0][1].get('due')
     api.set_date_for_block(items[0][0].course_key, items[0][0], 'due', assignment_date)
     # Specify the actual assignment due date so this will return true
     schedules = api.get_schedules_with_due_date(items[0][0].course_key, datetime.date(assignment_date))
     assert len(schedules) > 0
     for schedule in schedules:
         assert schedule.enrollment.course_id == items[0][0].course_key
         assert schedule.enrollment.user.id == self.user.id
Пример #2
0
    def get_schedules(self):
        course_key = CourseKey.from_string(self.course_id)
        target_date = self.target_datetime.date()
        schedules = get_schedules_with_due_date(course_key, target_date).filter(
            self.experience_filter,
            active=True,
            enrollment__user__is_active=True,
        )

        template_context = get_base_template_context(self.site)
        for schedule in schedules:
            enrollment = schedule.enrollment
            course = schedule.enrollment.course
            user = enrollment.user
            start_date = schedule.start_date
            LOG.info(u'Received a schedule for user {} in course {} for date {}'.format(
                user.username,
                self.course_id,
                target_date,
            ))

            try:
                week_highlights, week_num = get_next_section_highlights(user, course.id, start_date, target_date)
            except CourseUpdateDoesNotExist:
                LOG.warning(
                    u'Weekly highlights for user {} of course {} does not exist or is disabled'.format(
                        user, course.id
                    )
                )
                # continue to the next schedule, don't yield an email for this one
                continue
            unsubscribe_url = None
            if (COURSE_UPDATE_SHOW_UNSUBSCRIBE_WAFFLE_SWITCH.is_enabled() and
                    'bulk_email_optout' in settings.ACE_ENABLED_POLICIES):
                unsubscribe_url = reverse('bulk_email_opt_out', kwargs={
                    'token': UsernameCipher.encrypt(user.username),
                    'course_id': str(enrollment.course_id),
                })

            template_context.update({
                'course_name': course.display_name,
                'course_url': _get_trackable_course_home_url(enrollment.course_id),
                'week_num': week_num,
                'week_highlights': week_highlights,
                # This is used by the bulk email optout policy
                'course_ids': [str(enrollment.course_id)],
                'unsubscribe_url': unsubscribe_url,
            })
            template_context.update(_get_upsell_information_for_schedule(user, schedule))

            yield (user, enrollment.course.closest_released_language, template_context, course.self_paced)
Пример #3
0
 def test_get_schedules_with_due_date_for_abs_user_dates(self):
     items = make_items(with_relative=True)
     api.set_dates_for_course(items[0][0].course_key, items)
     assignment_date = items[0][1].get('due')
     api.set_date_for_block(items[0][0].course_key, items[0][0], 'due', assignment_date, user=self.user)
     models.UserDate.objects.create(
         abs_date=assignment_date,
         user=self.user,
         content_date=models.ContentDate.objects.first(),
     )
     # Specify the actual assignment due date so this will return true
     schedules = api.get_schedules_with_due_date(items[0][0].course_key, assignment_date.date())
     assert len(schedules) == 1  # Make sure there's only one schedule, we should not have duplicates
     assert schedules[0].enrollment.course_id == items[0][0].course_key
     assert schedules[0].enrollment.user.id == self.user.id
Пример #4
0
 def test_get_schedules_with_due_date_for_rel_date(self):
     items = make_items(with_relative=False)
     api.set_dates_for_course(items[0][0].course_key, items)
     relative_date = timedelta(days=2)
     api.set_date_for_block(items[0][0].course_key, items[0][0], 'due', relative_date)
     assignment_date = items[0][1].get('due') + relative_date
     # Move the schedule's start to the first assignment's original due since it's now offset
     self.schedule.start_date = items[0][1].get('due')
     self.schedule.save()
     # Specify the actual assignment due date so this will return true
     schedules = api.get_schedules_with_due_date(items[0][0].course_key, assignment_date.date())
     assert len(schedules) > 0
     for schedule in schedules:
         assert schedule.enrollment.course_id == items[0][0].course_key
         assert schedule.enrollment.user.id == self.user.id