• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python api.get_course_content_milestones函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中milestones.api.get_course_content_milestones函数的典型用法代码示例。如果您正苦于以下问题:Python get_course_content_milestones函数的具体用法?Python get_course_content_milestones怎么用?Python get_course_content_milestones使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_remove_content_references

    def test_remove_content_references(self):
        """ Unit Test: test_remove_content_references """
        # Add a course dependency on the test milestone
        api.add_course_milestone(
            self.test_course_key,
            self.relationship_types['REQUIRES'],
            self.test_milestone
        )
        self.assertEqual(len(api.get_course_milestones(self.test_course_key)), 1)

        # Add a content fulfillment for the test milestone
        api.add_course_content_milestone(
            self.test_course_key,
            self.test_content_key,
            self.relationship_types['FULFILLS'],
            self.test_milestone
        )
        milestones = api.get_course_content_milestones(self.test_course_key, self.test_content_key)
        self.assertEqual(len(milestones), 1)

        # Remove the content dependency
        with self.assertNumQueries(2):
            api.remove_content_references(self.test_content_key)
        milestones = api.get_course_content_milestones(self.test_course_key, self.test_content_key)
        self.assertEqual(len(milestones), 0)
开发者ID:edx,项目名称:edx-milestones,代码行数:25,代码来源:test_api.py


示例2: test_add_course_content_milestone

 def test_add_course_content_milestone(self):
     """ Unit Test: test_add_course_content_milestone """
     with self.assertNumQueries(3):
         api.add_course_content_milestone(
             self.test_course_key,
             self.test_content_key,
             self.relationship_types['REQUIRES'],
             self.test_milestone
         )
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES']
     )
     self.assertEqual(len(requirer_milestones), 1)
     with self.assertNumQueries(3):
         api.add_course_content_milestone(
             self.test_prerequisite_course_key,
             self.test_content_key,
             self.relationship_types['FULFILLS'],
             self.test_milestone,
             {'min_score': 80}
         )
     fulfiller_milestones = api.get_course_content_milestones(
         self.test_prerequisite_course_key,
         self.test_content_key,
         self.relationship_types['FULFILLS']
     )
     self.assertEqual(len(fulfiller_milestones), 1)
开发者ID:edx,项目名称:edx-milestones,代码行数:29,代码来源:test_api.py


示例3: get_course_content_milestones

def get_course_content_milestones(course_id, content_id=None, relationship='requires', user_id=None):
    """
    Client API operation adapter/wrapper
    Uses the request cache to store all of a user's
    milestones

    Returns all content blocks in a course if content_id is None, otherwise it just returns that
    specific content block.
    """
    if not settings.FEATURES.get('MILESTONES_APP'):
        return []

    if user_id is None:
        return milestones_api.get_course_content_milestones(course_id, content_id, relationship)

    request_cache_dict = get_cache(REQUEST_CACHE_NAME)
    if user_id not in request_cache_dict:
        request_cache_dict[user_id] = {}

    if relationship not in request_cache_dict[user_id]:
        request_cache_dict[user_id][relationship] = milestones_api.get_course_content_milestones(
            course_key=course_id,
            relationship=relationship,
            user={"id": user_id}
        )

    if content_id is None:
        return request_cache_dict[user_id][relationship]

    return [m for m in request_cache_dict[user_id][relationship] if m['content_id'] == six.text_type(content_id)]
开发者ID:cpennington,项目名称:edx-platform,代码行数:30,代码来源:milestones_helpers.py


示例4: test_remove_course_content_milestone

 def test_remove_course_content_milestone(self):
     """ Unit Test: test_remove_course_content_milestone """
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES']
     )
     self.assertEqual(len(requirer_milestones), 1)
     with self.assertNumQueries(2):
         api.remove_course_content_milestone(
             self.test_course_key,
             self.test_content_key,
             self.test_milestone
         )
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key,
         self.test_content_key
     )
     self.assertEqual(len(requirer_milestones), 0)
开发者ID:edx,项目名称:edx-milestones,代码行数:25,代码来源:test_api.py


示例5: test_add_course_content_milestone_inactive_to_active_update_requirements

 def test_add_course_content_milestone_inactive_to_active_update_requirements(self):
     """ Unit Test: test_add_course_content_milestone_inactive_to_active_update_requirement """
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone,
         {'min_score': 60}
     )
     api.remove_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.test_milestone
     )
     with self.assertNumQueries(3):
         api.add_course_content_milestone(
             self.test_course_key,
             self.test_content_key,
             self.relationship_types['REQUIRES'],
             self.test_milestone,
             {'min_score': 80}
         )
     milestone = api.get_course_content_milestones(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES']
     )
     for m in milestone:
         self.assertEqual(m['requirements'], {'min_score': 80})
开发者ID:edx,项目名称:edx-milestones,代码行数:29,代码来源:test_api.py


示例6: _fulfill_content_milestones

 def _fulfill_content_milestones(user, course_key, content_key):
     """
     Internal helper to handle milestone fulfillments for the specified content module
     """
     # Fulfillment Use Case: Entrance Exam
     # If this module is part of an entrance exam, we'll need to see if the student
     # has reached the point at which they can collect the associated milestone
     if settings.FEATURES.get('ENTRANCE_EXAMS', False):
         course = modulestore().get_course(course_key)
         content = modulestore().get_item(content_key)
         entrance_exam_enabled = getattr(course, 'entrance_exam_enabled', False)
         in_entrance_exam = getattr(content, 'in_entrance_exam', False)
         if entrance_exam_enabled and in_entrance_exam:
             exam_pct = _calculate_entrance_exam_score(user, course)
             if exam_pct >= course.entrance_exam_minimum_score_pct:
                 exam_key = UsageKey.from_string(course.entrance_exam_id)
                 relationship_types = milestones_api.get_milestone_relationship_types()
                 content_milestones = milestones_api.get_course_content_milestones(
                     course_key,
                     exam_key,
                     relationship=relationship_types['FULFILLS']
                 )
                 # Add each milestone to the user's set...
                 user = {'id': user.id}
                 for milestone in content_milestones:
                     milestones_api.add_user_milestone(user, milestone)
开发者ID:mrgnr,项目名称:edx-platform,代码行数:26,代码来源:module_render.py


示例7: get_course_content_milestones

def get_course_content_milestones(course_id, content_id, relationship):
    """
    Client API operation adapter/wrapper
    """
    if not settings.FEATURES.get('MILESTONES_APP', False):
        return []
    from milestones import api as milestones_api
    return milestones_api.get_course_content_milestones(course_id, content_id, relationship)
开发者ID:adoosii,项目名称:edx-platform,代码行数:8,代码来源:milestones_helpers.py


示例8: remove_course_content_user_milestones

def remove_course_content_user_milestones(course_key, content_key, user, relationship):
    """
    Removes the specified User-Milestone link from the system for the specified course content module.
    """
    if not settings.FEATURES.get('MILESTONES_APP'):
        return []

    course_content_milestones = milestones_api.get_course_content_milestones(course_key, content_key, relationship)
    for milestone in course_content_milestones:
        milestones_api.remove_user_milestone({'id': user.id}, milestone)
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:10,代码来源:milestones_helpers.py


示例9: test_remove_course_content_milestone_missing_milestone

 def test_remove_course_content_milestone_missing_milestone(self):
     """ Unit Test: test_remove_course_content_milestone_missing_milestone """
     with self.assertNumQueries(1):
         api.remove_course_content_milestone(
             self.test_course_key,
             self.test_content_key,
             self.test_milestone
         )
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key,
         self.test_content_key
     )
     self.assertEqual(len(requirer_milestones), 0)
开发者ID:edx,项目名称:edx-milestones,代码行数:13,代码来源:test_api.py


示例10: get_course_content_milestones

def get_course_content_milestones(course_id, content_id, relationship, user_id=None):
    """
    Client API operation adapter/wrapper
    Uses the request cache to store all of a user's
    milestones
    """
    if not settings.FEATURES.get('MILESTONES_APP'):
        return []

    if user_id is None:
        return milestones_api.get_course_content_milestones(course_id, content_id, relationship)

    request_cache_dict = request_cache.get_cache(REQUEST_CACHE_NAME)
    if user_id not in request_cache_dict:
        request_cache_dict[user_id] = {}

    if relationship not in request_cache_dict[user_id]:
        request_cache_dict[user_id][relationship] = milestones_api.get_course_content_milestones(
            course_key=course_id,
            relationship=relationship,
            user={"id": user_id}
        )

    return [m for m in request_cache_dict[user_id][relationship] if m['content_id'] == content_id]
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:24,代码来源:milestones_helpers.py


示例11: test_get_course_content_milestones_with_unfulfilled_user_milestones

 def test_get_course_content_milestones_with_unfulfilled_user_milestones(self):
     """ Unit Test: test_get_course_content_milestones_with_unfulfilled_user_milestones """
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     with self.assertNumQueries(2):
         requirer_milestones = api.get_course_content_milestones(
             self.test_course_key,
             self.test_content_key,
             self.relationship_types['REQUIRES'],
             {'id': self.test_user.id}
         )
     self.assertEqual(len(requirer_milestones), 1)
开发者ID:edx,项目名称:edx-milestones,代码行数:16,代码来源:test_api.py


示例12: _fulfill_content_milestones

 def _fulfill_content_milestones(course_key, content_key, user_id):  # pylint: disable=unused-argument
     """
     Internal helper to handle milestone fulfillments for the specified content module
     """
     # Fulfillment Use Case: Entrance Exam
     # If this module is part of an entrance exam, we'll need to see if the student
     # has reached the point at which they can collect the associated milestone
     if settings.FEATURES.get('ENTRANCE_EXAMS', False):
         course = modulestore().get_course(course_key)
         content = modulestore().get_item(content_key)
         entrance_exam_enabled = getattr(course, 'entrance_exam_enabled', False)
         in_entrance_exam = getattr(content, 'in_entrance_exam', False)
         if entrance_exam_enabled and in_entrance_exam:
             exam_key = UsageKey.from_string(course.entrance_exam_id)
             exam_descriptor = modulestore().get_item(exam_key)
             exam_modules = yield_dynamic_descriptor_descendents(
                 exam_descriptor,
                 inner_get_module
             )
             ignore_categories = ['course', 'chapter', 'sequential', 'vertical']
             module_pcts = []
             exam_pct = 0
             for module in exam_modules:
                 if module.graded and module.category not in ignore_categories:
                     module_pct = 0
                     try:
                         student_module = StudentModule.objects.get(
                             module_state_key=module.scope_ids.usage_id,
                             student_id=user_id
                         )
                         if student_module.max_grade:
                             module_pct = student_module.grade / student_module.max_grade
                     except StudentModule.DoesNotExist:
                         pass
                     module_pcts.append(module_pct)
             exam_pct = sum(module_pcts) / float(len(module_pcts))
             if exam_pct >= course.entrance_exam_minimum_score_pct:
                 relationship_types = milestones_api.get_milestone_relationship_types()
                 content_milestones = milestones_api.get_course_content_milestones(
                     course_key,
                     exam_key,
                     relationship=relationship_types['FULFILLS']
                 )
                 # Add each milestone to the user's set...
                 user = {'id': user_id}
                 for milestone in content_milestones:
                     milestones_api.add_user_milestone(user, milestone)
开发者ID:feedbackfruits,项目名称:edx-platform,代码行数:47,代码来源:module_render.py


示例13: test_get_gated_content

    def test_get_gated_content(self):
        """ Test test_get_gated_content """

        mock_user = MagicMock()
        mock_user.id.return_value = 1

        self.assertEqual(gating_api.get_gated_content(self.course, mock_user), [])

        gating_api.add_prerequisite(self.course.id, self.seq1.location)
        gating_api.set_required_content(self.course.id, self.seq2.location, self.seq1.location, 100)
        milestone = milestones_api.get_course_content_milestones(self.course.id, self.seq2.location, 'requires')[0]

        self.assertEqual(gating_api.get_gated_content(self.course, mock_user), [unicode(self.seq2.location)])

        milestones_api.add_user_milestone({'id': mock_user.id}, milestone)

        self.assertEqual(gating_api.get_gated_content(self.course, mock_user), [])
开发者ID:10clouds,项目名称:edx-platform,代码行数:17,代码来源:test_api.py


示例14: find_gating_milestones

def find_gating_milestones(course_key, content_key=None, relationship=None, user=None):
    """
    Finds gating milestone dicts related to the given supplied parameters.

    Arguments:
        course_key (str|CourseKey): The course key
        content_key (str|UsageKey): The content usage key
        relationship (str): The relationship type (e.g. 'requires')
        user (dict): The user dict (e.g. {'id': 4})

    Returns:
        list: A list of milestone dicts
    """
    return [
        m for m in milestones_api.get_course_content_milestones(course_key, content_key, relationship, user)
        if GATING_NAMESPACE_QUALIFIER in m.get('namespace')
    ]
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:17,代码来源:api.py


示例15: test_get_gated_content

    def test_get_gated_content(self):
        """
        Verify staff bypasses gated content and student gets list of unfulfilled prerequisites.
        """

        staff = UserFactory(is_staff=True)
        student = UserFactory(is_staff=False)

        self.assertEqual(gating_api.get_gated_content(self.course, staff), [])
        self.assertEqual(gating_api.get_gated_content(self.course, student), [])

        gating_api.add_prerequisite(self.course.id, self.seq1.location)
        gating_api.set_required_content(self.course.id, self.seq2.location, self.seq1.location, 100)
        milestone = milestones_api.get_course_content_milestones(self.course.id, self.seq2.location, 'requires')[0]

        self.assertEqual(gating_api.get_gated_content(self.course, staff), [])
        self.assertEqual(gating_api.get_gated_content(self.course, student), [unicode(self.seq2.location)])

        milestones_api.add_user_milestone({'id': student.id}, milestone)  # pylint: disable=no-member

        self.assertEqual(gating_api.get_gated_content(self.course, student), [])
开发者ID:mreyk,项目名称:edx-platform,代码行数:21,代码来源:test_api.py


示例16: test_get_course_content_milestones_without_content_key

 def test_get_course_content_milestones_without_content_key(self):
     """ Unit Test: test_get_course_content_milestones_without_content_key """
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_alternate_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     with self.assertNumQueries(2):
         requirer_milestones = api.get_course_content_milestones(
             self.test_course_key,
             None,
             self.relationship_types['REQUIRES']
         )
     self.assertEqual(len(requirer_milestones), 2)
开发者ID:edx,项目名称:edx-milestones,代码行数:21,代码来源:test_api.py


示例17: test_get_course_content_milestones_with_invalid_relationship

 def test_get_course_content_milestones_with_invalid_relationship(self):
     """ Unit Test: test_get_course_content_milestones_with_invalid_relationship """
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_alternate_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     with self.assertNumQueries(1):
         requirer_milestones = api.get_course_content_milestones(
             self.test_course_key,
             self.test_content_key,
             'INVALID RELATIONSHIP TYPE'
         )
     self.assertEqual(len(requirer_milestones), 0)
开发者ID:edx,项目名称:edx-milestones,代码行数:21,代码来源:test_api.py


示例18: test_contentstore_views_entrance_exam_post

        def test_contentstore_views_entrance_exam_post(self):
            """
            Unit Test: test_contentstore_views_entrance_exam_post
            """
            resp = self.client.post(self.exam_url, {}, http_accept='application/json')
            self.assertEqual(resp.status_code, 201)
            resp = self.client.get(self.exam_url)
            self.assertEqual(resp.status_code, 200)

            # Reload the test course now that the exam module has been added
            self.course = modulestore().get_course(self.course.id)
            metadata = CourseMetadata.fetch_all(self.course)
            self.assertTrue(metadata['entrance_exam_enabled'])
            self.assertIsNotNone(metadata['entrance_exam_minimum_score_pct'])
            self.assertIsNotNone(metadata['entrance_exam_id']['value'])
            self.assertTrue(len(milestones_api.get_course_milestones(unicode(self.course.id))))
            content_milestones = milestones_api.get_course_content_milestones(
                unicode(self.course.id),
                metadata['entrance_exam_id']['value'],
                self.milestone_relationship_types['FULFILLS']
            )
            self.assertTrue(len(content_milestones))
开发者ID:akbargumbira,项目名称:Labster.EdX,代码行数:22,代码来源:test_entrance_exam.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python api.get_course_milestones函数代码示例发布时间:2022-05-27
下一篇:
Python api.add_user_milestone函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap