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

Python api.add_user_milestone函数代码示例

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

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



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

示例1: test_add_milestone_inactive_milestone_with_relationships_propagate_false

    def test_add_milestone_inactive_milestone_with_relationships_propagate_false(self):
        """ Unit Test: test_add_milestone_inactive_milestone_with_relationships_propagate_false"""
        milestone_data = {
            'name': 'local_milestone',
            'display_name': 'Local Milestone',
            'namespace': six.text_type(self.test_course_key),
            'description': 'Local Milestone Description'
        }
        milestone = api.add_milestone(milestone_data)
        api.add_course_milestone(
            self.test_course_key,
            self.relationship_types['REQUIRES'],
            milestone
        )
        api.add_course_content_milestone(
            self.test_course_key,
            self.test_content_key,
            self.relationship_types['FULFILLS'],
            milestone
        )
        api.add_user_milestone(self.serialized_test_user, milestone)
        self.assertGreater(milestone['id'], 0)
        api.remove_milestone(milestone['id'])

        with self.assertNumQueries(3):
            milestone = api.add_milestone(milestone_data, propagate=False)
开发者ID:edx,项目名称:edx-milestones,代码行数:26,代码来源:test_api.py


示例2: test_remove_user_milestone

 def test_remove_user_milestone(self):
     """ Unit Test: test_remove_user_milestone """
     api.add_user_milestone(self.serialized_test_user, self.test_milestone)
     self.assertTrue(api.user_has_milestone(self.serialized_test_user, self.test_milestone))
     with self.assertNumQueries(2):
         api.remove_user_milestone(self.serialized_test_user, self.test_milestone)
     self.assertFalse(api.user_has_milestone(self.serialized_test_user, self.test_milestone))
开发者ID:edx,项目名称:edx-milestones,代码行数:7,代码来源:test_api.py


示例3: test_add_user_milestone_inactive_to_active

 def test_add_user_milestone_inactive_to_active(self):
     """ Unit Test: test_add_user_milestone """
     api.add_user_milestone(self.serialized_test_user, self.test_milestone)
     api.remove_user_milestone(self.serialized_test_user, self.test_milestone)
     with self.assertNumQueries(4):
         api.add_user_milestone(self.serialized_test_user, self.test_milestone)
     self.assertTrue(api.user_has_milestone(self.serialized_test_user, self.test_milestone))
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:7,代码来源:test_api.py


示例4: _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


示例5: test_add_user_milestone_bogus_user

 def test_add_user_milestone_bogus_user(self):
     """ Unit Test: test_add_user_milestone_bogus_user """
     with self.assertNumQueries(0):
         with self.assertRaises(exceptions.InvalidUserException):
             api.add_user_milestone({'identifier': 'abcd'}, self.test_milestone)
     with self.assertNumQueries(0):
         with self.assertRaises(exceptions.InvalidUserException):
             api.add_user_milestone(None, self.test_milestone)
开发者ID:edx,项目名称:edx-milestones,代码行数:8,代码来源:test_api.py


示例6: fulfill_course_milestone

def fulfill_course_milestone(course_key, user):
    """
    Marks the course specified by the given course_key as complete for the given user.
    If any other courses require this course as a prerequisite, their milestones will be appropriately updated.
    """
    if settings.FEATURES.get('MILESTONES_APP', False):
        course_milestones = get_course_milestones(course_key=course_key, relationship="fulfills")
        for milestone in course_milestones:
            add_user_milestone({'id': user.id}, milestone)
开发者ID:mrgnr,项目名称:edx-platform,代码行数:9,代码来源:milestones_helpers.py


示例7: evaluate_prerequisite

def evaluate_prerequisite(course, prereq_content_key, user_id):
    """
    Finds the parent subsection of the content in the course and evaluates
    any milestone relationships attached to that subsection. If the calculated
    grade of the prerequisite subsection meets the minimum score required by
    dependent subsections, the related milestone will be fulfilled for the user.

    Arguments:
        user_id (int): ID of User for which evaluation should occur
        course (CourseModule): The course
        prereq_content_key (UsageKey): The prerequisite content usage key

    Returns:
        None
    """
    xblock = modulestore().get_item(prereq_content_key)
    sequential = _get_xblock_parent(xblock, 'sequential')
    if sequential:
        prereq_milestone = gating_api.get_gating_milestone(
            course.id,
            sequential.location.for_branch(None),
            'fulfills'
        )
        if prereq_milestone:
            gated_content_milestones = defaultdict(list)
            for milestone in gating_api.find_gating_milestones(course.id, None, 'requires'):
                gated_content_milestones[milestone['id']].append(milestone)

            gated_content = gated_content_milestones.get(prereq_milestone['id'])
            if gated_content:
                from courseware.grades import get_module_score
                user = User.objects.get(id=user_id)
                score = get_module_score(user, course, sequential) * 100
                for milestone in gated_content:
                    # Default minimum score to 100
                    min_score = 100
                    requirements = milestone.get('requirements')
                    if requirements:
                        try:
                            min_score = int(requirements.get('min_score'))
                        except (ValueError, TypeError):
                            log.warning(
                                'Failed to find minimum score for gating milestone %s, defaulting to 100',
                                json.dumps(milestone)
                            )

                    if score >= min_score:
                        milestones_api.add_user_milestone({'id': user_id}, prereq_milestone)
                    else:
                        milestones_api.remove_user_milestone({'id': user_id}, prereq_milestone)
开发者ID:10clouds,项目名称:edx-platform,代码行数:50,代码来源:api.py


示例8: fulfill_course_milestone

def fulfill_course_milestone(course_key, user):
    """
    Marks the course specified by the given course_key as complete for the given user.
    If any other courses require this course as a prerequisite, their milestones will be appropriately updated.
    """
    if not settings.FEATURES.get('MILESTONES_APP'):
        return None
    try:
        course_milestones = milestones_api.get_course_milestones(course_key=course_key, relationship="fulfills")
    except InvalidMilestoneRelationshipTypeException:
        # we have not seeded milestone relationship types
        seed_milestone_relationship_types()
        course_milestones = milestones_api.get_course_milestones(course_key=course_key, relationship="fulfills")
    for milestone in course_milestones:
        milestones_api.add_user_milestone({'id': user.id}, milestone)
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:15,代码来源:milestones_helpers.py


示例9: add_user_milestone

def add_user_milestone(user, milestone):
    """
    Client API operation adapter/wrapper
    """
    if not settings.FEATURES.get('MILESTONES_APP'):
        return None
    return milestones_api.add_user_milestone(user, milestone)
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:7,代码来源:milestones_helpers.py


示例10: _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


示例11: 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


示例12: test_fetch_user_milestones_missing_match_criteria_throws_exception

    def test_fetch_user_milestones_missing_match_criteria_throws_exception(self):
        """ Unit Test: test_fetch_user_milestones_missing_match_criteria_throws_exception """
        milestone1 = api.add_milestone({
            'display_name': 'Test Milestone',
            'name': 'test_milestone',
            'namespace': unicode(self.test_course_key),
            'description': 'Test Milestone Description',
        })
        api.add_user_milestone(self.serialized_test_user, milestone1)

        with self.assertRaises(exceptions.InvalidMilestoneException):
            data.fetch_user_milestones(self.serialized_test_user, {})

        # Ensure we cover all remaining logical branches per coverage.py
        data.fetch_user_milestones(
            self.serialized_test_user,
            {'id': milestone1['id']}
        )
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:18,代码来源:test_data.py


示例13: test_get_course_content_milestones_with_fulfilled_user_milestones

 def test_get_course_content_milestones_with_fulfilled_user_milestones(self):
     """ Unit Test: test_get_course_content_milestones_with_fulfilled_user_milestones """
     user = {'id': self.test_user.id}
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     api.add_user_milestone(user, 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), 0)
开发者ID:edx,项目名称:edx-milestones,代码行数:18,代码来源:test_api.py


示例14: 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


示例15: test_get_course_milestones_fulfillment_paths


#.........这里部分代码省略.........
            UsageKey.from_string('i4x://the/content/key/123456789'),
            self.relationship_types['FULFILLS'],
            local_milestone_2
        )
        api.add_course_content_milestone(
            self.test_course_key,
            UsageKey.from_string('i4x://the/content/key/123456789'),
            self.relationship_types['FULFILLS'],
            local_milestone_3
        )
        api.add_course_content_milestone(
            self.test_course_key,
            UsageKey.from_string('i4x://the/content/key/987654321'),
            self.relationship_types['FULFILLS'],
            local_milestone_3
        )

        # Confirm the starting state for this test (user has no milestones, course requires three)
        self.assertEqual(
            len(api.get_user_milestones(self.serialized_test_user, namespace=namespace)), 0)
        self.assertEqual(
            len(api.get_course_required_milestones(self.test_course_key, self.serialized_test_user)),
            3
        )
        # Check the possible fulfillment paths for the milestones for this course
        with self.assertNumQueries(8):
            paths = api.get_course_milestones_fulfillment_paths(
                self.test_course_key,
                self.serialized_test_user
            )

        # Set up the key values we'll use to access/assert the response
        milestone_key_1 = '{}.{}'.format(local_milestone_1['namespace'], local_milestone_1['name'])
        milestone_key_2 = '{}.{}'.format(local_milestone_2['namespace'], local_milestone_2['name'])
        milestone_key_3 = '{}.{}'.format(local_milestone_3['namespace'], local_milestone_3['name'])

        # First round of assertions
        self.assertEqual(len(paths[milestone_key_1]['courses']), 1)
        self.assertIsNone(paths[milestone_key_1].get('content'))
        self.assertEqual(len(paths[milestone_key_2]['courses']), 1)
        self.assertEqual(len(paths[milestone_key_2]['content']), 1)
        self.assertIsNone(paths[milestone_key_3].get('courses'))
        self.assertEqual(len(paths[milestone_key_3]['content']), 2)

        # Collect the first milestone (two should remain)
        api.add_user_milestone(self.serialized_test_user, local_milestone_1)
        self.assertEqual(
            len(api.get_user_milestones(self.serialized_test_user, namespace=namespace)), 1)
        self.assertEqual(
            len(api.get_course_required_milestones(self.test_course_key, self.serialized_test_user)),
            2
        )
        # Check the remaining fulfillment paths for the milestones for this course
        with self.assertNumQueries(6):
            paths = api.get_course_milestones_fulfillment_paths(
                self.test_course_key,
                self.serialized_test_user
            )
        self.assertIsNone(paths.get(milestone_key_1))
        self.assertEqual(len(paths[milestone_key_2]['courses']), 1)
        self.assertEqual(len(paths[milestone_key_2]['content']), 1)
        self.assertIsNone(paths[milestone_key_3].get('courses'))
        self.assertEqual(len(paths[milestone_key_3]['content']), 2)

        # Collect the second milestone (one should remain)
        api.add_user_milestone(self.serialized_test_user, local_milestone_2)
        self.assertEqual(
            len(api.get_user_milestones(self.serialized_test_user, namespace=namespace)), 2)
        self.assertEqual(
            len(api.get_course_required_milestones(self.test_course_key, self.serialized_test_user)),
            1
        )
        # Check the remaining fulfillment paths for the milestones for this course
        with self.assertNumQueries(4):
            paths = api.get_course_milestones_fulfillment_paths(
                self.test_course_key,
                self.serialized_test_user
            )
        self.assertIsNone(paths.get(milestone_key_1))
        self.assertIsNone(paths.get(milestone_key_2))
        self.assertIsNone(paths[milestone_key_3].get('courses'))
        self.assertEqual(len(paths[milestone_key_3]['content']), 2)

        # Collect the third milestone
        api.add_user_milestone(self.serialized_test_user, local_milestone_3)
        self.assertEqual(
            len(api.get_user_milestones(self.serialized_test_user, namespace=namespace)), 3)
        self.assertEqual(
            len(api.get_course_required_milestones(self.test_course_key, self.serialized_test_user)),
            0
        )
        # Check the remaining fulfillment paths for the milestones for this course
        with self.assertNumQueries(2):
            paths = api.get_course_milestones_fulfillment_paths(
                self.test_course_key,
                self.serialized_test_user
            )
        self.assertIsNone(paths.get(milestone_key_1))
        self.assertIsNone(paths.get(milestone_key_2))
        self.assertIsNone(paths.get(milestone_key_3))
开发者ID:edx,项目名称:edx-milestones,代码行数:101,代码来源:test_api.py


示例16: test_get_course_unfulfilled_milestones

    def test_get_course_unfulfilled_milestones(self):
        """ Unit Test: test_get_course_unfulfilled_milestones """
        namespace = 'test_get_milestones'
        milestone1 = api.add_milestone({
            'name': 'localmilestone1',
            'display_name': 'Local Milestone 1',
            'namespace': namespace,
            'description': 'Local Milestone 1 Description'
        })
        api.add_course_milestone(
            self.test_course_key,
            self.relationship_types['REQUIRES'],
            milestone1
        )

        milestone2 = api.add_milestone({
            'name': 'localmilestone2',
            'display_name': 'Local Milestone 2',
            'namespace': namespace,
            'description': 'Local Milestone 2 Description'
        })
        api.add_course_milestone(
            self.test_course_key,
            self.relationship_types['REQUIRES'],
            milestone2
        )

        # Confirm that the course has only two milestones, and that the User still needs to collect both
        course_milestones = api.get_course_milestones(self.test_course_key)
        self.assertEqual(len(course_milestones), 2)
        with self.assertNumQueries(2):
            required_milestones = api.get_course_required_milestones(
                self.test_course_key,
                self.serialized_test_user
            )

        # Link the User to Milestone 2 (this one is now 'collected')
        api.add_user_milestone(self.serialized_test_user, milestone2)
        user_milestones = api.get_user_milestones(self.serialized_test_user, namespace=namespace)
        self.assertEqual(len(user_milestones), 1)
        self.assertEqual(user_milestones[0]['id'], milestone2['id'])

        # Only Milestone 1 should be listed as 'required' for the course at this point
        with self.assertNumQueries(2):
            required_milestones = api.get_course_required_milestones(
                self.test_course_key,
                self.serialized_test_user
            )
        self.assertEqual(len(required_milestones), 1)
        self.assertEqual(required_milestones[0]['id'], milestone1['id'])

        # Link the User to Milestone 1 (this one is now 'collected', as well)
        api.add_user_milestone(self.serialized_test_user, milestone1)
        user_milestones = api.get_user_milestones(self.serialized_test_user, namespace=namespace)
        self.assertEqual(len(user_milestones), 2)

        # And there should be no more Milestones required for this User+Course
        with self.assertNumQueries(2):
            required_milestones = api.get_course_required_milestones(
                self.test_course_key,
                self.serialized_test_user
            )
        self.assertEqual(len(required_milestones), 0)
开发者ID:edx,项目名称:edx-milestones,代码行数:63,代码来源:test_api.py


示例17: test_get_user_milestones

 def test_get_user_milestones(self):
     """ Unit Test: test_get_user_milestones """
     with self.assertNumQueries(2):
         api.add_user_milestone(self.serialized_test_user, self.test_milestone)
     self.assertTrue(api.user_has_milestone(self.serialized_test_user, self.test_milestone))
开发者ID:edx,项目名称:edx-milestones,代码行数:5,代码来源:test_api.py


示例18: test_add_user_milestone_active_exists

 def test_add_user_milestone_active_exists(self):
     """ Unit Test: test_add_user_milestone """
     api.add_user_milestone(self.serialized_test_user, self.test_milestone)
     with self.assertNumQueries(1):
         api.add_user_milestone(self.serialized_test_user, self.test_milestone)
     self.assertTrue(api.user_has_milestone(self.serialized_test_user, self.test_milestone))
开发者ID:edx,项目名称:edx-milestones,代码行数:6,代码来源:test_api.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python api.get_course_content_milestones函数代码示例发布时间:2022-05-27
下一篇:
Python api.add_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