def render_to_fragment(self, request, course_id, user_access, **kwargs):
        """
        Renders a course message fragment for the specified course.
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user, 'load', course_key)

        # Get time until the start date, if already started, or no start date, value will be zero or negative
        now = datetime.now(UTC)
        already_started = course.start and now > course.start
        days_until_start_string = "started" if already_started else format_timedelta(
            course.start - now, locale=to_locale(get_language())
        )
        course_start_data = {
            'course_start_date': format_date(course.start, locale=to_locale(get_language())),
            'already_started': already_started,
            'days_until_start_string': days_until_start_string
        }

        # Register the course home messages to be loaded on the page
        _register_course_home_messages(request, course, user_access, course_start_data)

        # Register course date alerts
        for course_date_block in get_course_date_blocks(course, request.user, request):
            course_date_block.register_alerts(request, course)

        # Register a course goal message, if appropriate
        # Only show the set course goal message for enrolled, unverified
        # users that have not yet set a goal in a course that allows for
        # verified statuses.
        user_goal = get_course_goal(auth.get_user(request), course_key)
        is_already_verified = CourseEnrollment.is_enrolled_as_verified(request.user, course_key)
        if has_course_goal_permission(request, course_id, user_access) and not is_already_verified and not user_goal:
            _register_course_goal_message(request, course)

        # Grab the relevant messages
        course_home_messages = list(CourseHomeMessages.user_messages(request))

        # Pass in the url used to set a course goal
        goal_api_url = get_goal_api_url(request)

        # Grab the logo
        image_src = 'course_experience/images/home_message_author.png'

        context = {
            'course_home_messages': course_home_messages,
            'goal_api_url': goal_api_url,
            'image_src': image_src,
            'course_id': course_id,
            'username': request.user.username,
        }

        html = render_to_string('course_experience/course-messages-fragment.html', context)
        return Fragment(html)
    def render_to_fragment(self, request, course_id, user_access, **kwargs):
        """
        Renders a course message fragment for the specified course.
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user, 'load', course_key)

        # Get time until the start date, if already started, or no start date, value will be zero or negative
        now = datetime.now(UTC)
        already_started = course.start and now > course.start
        days_until_start_string = "started" if already_started else format_timedelta(
            course.start - now, locale=to_locale(get_language())
        )
        course_start_data = {
            'course_start_date': format_date(course.start, locale=to_locale(get_language())),
            'already_started': already_started,
            'days_until_start_string': days_until_start_string
        }

        # Register the course home messages to be loaded on the page
        _register_course_home_messages(request, course, user_access, course_start_data)

        # Register course date alerts
        for course_date_block in get_course_date_blocks(course, request.user):
            course_date_block.register_alerts(request, course)

        # Register a course goal message, if appropriate
        # Only show the set course goal message for enrolled, unverified
        # users that have not yet set a goal in a course that allows for
        # verified statuses.
        user_goal = get_course_goal(auth.get_user(request), course_key)
        is_already_verified = CourseEnrollment.is_enrolled_as_verified(request.user, course_key)
        if has_course_goal_permission(request, course_id, user_access) and not is_already_verified and not user_goal:
            _register_course_goal_message(request, course)

        # Grab the relevant messages
        course_home_messages = list(CourseHomeMessages.user_messages(request))

        # Pass in the url used to set a course goal
        goal_api_url = get_goal_api_url(request)

        # Grab the logo
        image_src = 'course_experience/images/home_message_author.png'

        context = {
            'course_home_messages': course_home_messages,
            'goal_api_url': goal_api_url,
            'image_src': image_src,
            'course_id': course_id,
            'username': request.user.username,
        }

        html = render_to_string('course_experience/course-messages-fragment.html', context)
        return Fragment(html)
 def test_certificate_availability_alert(self, current_time, expected_message_html):
     """
     Verify the verified upgrade deadline alerts.
     """
     with freeze_time(current_time):
         block = CertificateAvailableDate(self.course, self.request.user)
         block.register_alerts(self.request, self.course)
         messages = list(CourseHomeMessages.user_messages(self.request))
         if expected_message_html:
             self.assertEqual(len(messages), 1)
             self.assertIn(expected_message_html, messages[0].message_html)
         else:
             self.assertEqual(len(messages), 0)
 def test_end_date_alert(self, current_time, expected_message_html):
     """
     Verify that course end date alerts are registered.
     """
     with freeze_time(current_time):
         block = CourseEndDate(self.course, self.request.user)
         block.register_alerts(self.request, self.course)
         messages = list(CourseHomeMessages.user_messages(self.request))
         if expected_message_html:
             self.assertEqual(len(messages), 1)
             self.assertIn(expected_message_html, messages[0].message_html)
         else:
             self.assertEqual(len(messages), 0)
예제 #5
0
 def test_certificate_availability_alert(self, current_time, expected_message_html):
     """
     Verify the verified upgrade deadline alerts.
     """
     with freeze_time(current_time):
         block = CertificateAvailableDate(self.course, self.request.user)
         block.register_alerts(self.request, self.course)
         messages = list(CourseHomeMessages.user_messages(self.request))
         if expected_message_html:
             self.assertEqual(len(messages), 1)
             self.assertIn(expected_message_html, messages[0].message_html)
         else:
             self.assertEqual(len(messages), 0)
예제 #6
0
 def test_end_date_alert(self, current_time, expected_message_html):
     """
     Verify that course end date alerts are registered.
     """
     with freeze_time(current_time):
         block = CourseEndDate(self.course, self.request.user)
         block.register_alerts(self.request, self.course)
         messages = list(CourseHomeMessages.user_messages(self.request))
         if expected_message_html:
             self.assertEqual(len(messages), 1)
             self.assertIn(expected_message_html, messages[0].message_html)
         else:
             self.assertEqual(len(messages), 0)
예제 #7
0
    def render_to_fragment(self, request, course_id, user_access, **kwargs):
        """
        Renders a course message fragment for the specified course.
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user, 'load', course_key)

        # Get time until the start date, if already started, or no start date, value will be zero or negative
        now = datetime.now(UTC())
        already_started = course.start and now > course.start
        days_until_start_string = "started" if already_started else format_timedelta(
            course.start - now, locale=to_locale(get_language()))
        course_start_data = {
            'course_start_date':
            format_date(course.start, locale=to_locale(get_language())),
            'already_started':
            already_started,
            'days_until_start_string':
            days_until_start_string
        }

        # Register the course home messages to be loaded on the page
        _register_course_home_messages(request, course_id, user_access,
                                       course_start_data)

        # Grab the relevant messages
        course_home_messages = list(CourseHomeMessages.user_messages(request))

        # Pass in the url used to set a course goal
        goal_api_url = reverse('course_goals_api:v0:course_goal-list',
                               request=request)

        # Grab the logo
        image_src = "course_experience/images/home_message_author.png"

        context = {
            'course_home_messages': course_home_messages,
            'goal_api_url': goal_api_url,
            'image_src': image_src,
            'course_id': course_id,
            'username': request.user.username,
        }

        html = render_to_string(
            'course_experience/course-messages-fragment.html', context)
        return Fragment(html)
예제 #8
0
    def render_to_fragment(self, request, course_id, user_access, **kwargs):
        """
        Renders a course message fragment for the specified course.
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user, 'load', course_key)

        # Get time until the start date, if already started, or no start date, value will be zero or negative
        now = datetime.now(UTC())
        already_started = course.start and now > course.start
        days_until_start_string = "started" if already_started else format_timedelta(
            course.start - now, locale=to_locale(get_language()))
        course_start_data = {
            'course_start_date':
            format_date(course.start, locale=to_locale(get_language())),
            'already_started':
            already_started,
            'days_until_start_string':
            days_until_start_string
        }

        # Register the course home messages to be loaded on the page
        self.register_course_home_messages(request, course, user_access,
                                           course_start_data)

        # Grab the relevant messages
        course_home_messages = list(CourseHomeMessages.user_messages(request))

        # Return None if user is enrolled and course has begun
        if user_access['is_enrolled'] and already_started:
            return None

        # Grab the logo
        image_src = "course_experience/images/home_message_author.png"

        context = {
            'course_home_messages': course_home_messages,
            'image_src': image_src,
        }

        html = render_to_string(
            'course_experience/course-messages-fragment.html', context)
        return Fragment(html)