当前位置: 首页>>代码示例>>Python>>正文


Python CourseHomeMessages.user_messages方法代码示例

本文整理汇总了Python中openedx.features.course_experience.CourseHomeMessages.user_messages方法的典型用法代码示例。如果您正苦于以下问题:Python CourseHomeMessages.user_messages方法的具体用法?Python CourseHomeMessages.user_messages怎么用?Python CourseHomeMessages.user_messages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openedx.features.course_experience.CourseHomeMessages的用法示例。


在下文中一共展示了CourseHomeMessages.user_messages方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_to_fragment

# 需要导入模块: from openedx.features.course_experience import CourseHomeMessages [as 别名]
# 或者: from openedx.features.course_experience.CourseHomeMessages import user_messages [as 别名]
    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)
开发者ID:TeachAtTUM,项目名称:edx-platform,代码行数:56,代码来源:course_home_messages.py

示例2: test_certificate_availability_alert

# 需要导入模块: from openedx.features.course_experience import CourseHomeMessages [as 别名]
# 或者: from openedx.features.course_experience.CourseHomeMessages import user_messages [as 别名]
 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)
开发者ID:lduarte1991,项目名称:edx-platform,代码行数:15,代码来源:test_date_summary.py

示例3: test_end_date_alert

# 需要导入模块: from openedx.features.course_experience import CourseHomeMessages [as 别名]
# 或者: from openedx.features.course_experience.CourseHomeMessages import user_messages [as 别名]
 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)
开发者ID:lduarte1991,项目名称:edx-platform,代码行数:15,代码来源:test_date_summary.py


注:本文中的openedx.features.course_experience.CourseHomeMessages.user_messages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。