Example #1
0
 def get_context_data(self, *args, **kwargs):
     context = super().get_context_data(*args, **kwargs)
     user = self.request.user
     context["student"] = self.student
     context["course"] = self.get_course(user)
     forecaster = Forecaster()
     context["task_items"] = forecaster.get_task_items(
         context["student"], context["course"]
     )
     if not self.request.GET.get("completed_tasks"):
         context["task_items"] = [
             item for item in context["task_items"] if "coursework" not in item
         ]
     return context
    def test_no_forecast_course_not_running(self):
        """A course that isn't running will not forecast dates."""
        today = timezone.localdate()
        user = self.make_user()
        school_year = SchoolYearFactory(
            school=user.school,
            start_date=today + relativedelta(years=1, month=1, day=1),
            end_date=today + relativedelta(years=1, month=12, day=31),
            days_of_week=SchoolYear.ALL_DAYS,
        )
        enrollment = EnrollmentFactory(student__school=user.school,
                                       grade_level__school_year=school_year)
        course = CourseFactory(grade_levels=[enrollment.grade_level],
                               days_of_week=Course.NO_DAYS)
        CourseTaskFactory(course=course)
        forecaster = Forecaster()

        items = forecaster.get_task_items(enrollment.student, course)

        task_item = items[0]
        assert "planned_date" not in task_item
    def test_planned_dates_for_future_school_years(self):
        """The planned dates for a future school year match with the year."""
        today = timezone.localdate()
        user = self.make_user()
        school_year = SchoolYearFactory(
            school=user.school,
            start_date=today + relativedelta(years=1, month=1, day=1),
            end_date=today + relativedelta(years=1, month=12, day=31),
            days_of_week=SchoolYear.ALL_DAYS,
        )
        enrollment = EnrollmentFactory(student__school=user.school,
                                       grade_level__school_year=school_year)
        course = CourseFactory(grade_levels=[enrollment.grade_level],
                               days_of_week=Course.ALL_DAYS)
        CourseTaskFactory(course=course)
        forecaster = Forecaster()

        items = forecaster.get_task_items(enrollment.student, course)

        task_item = items[0]
        assert task_item["planned_date"] == school_year.start_date