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


Python milestones_helpers.get_course_content_milestones函数代码示例

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


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

示例1: test_entrance_exam_milestone_removal

 def test_entrance_exam_milestone_removal(self):
     """
     Unit Test: test removal of entrance exam milestone content
     """
     parent_locator = unicode(self.course.location)
     created_block = create_xblock(
         parent_locator=parent_locator,
         user=self.user,
         category='chapter',
         display_name=('Entrance Exam'),
         is_entrance_exam=True
     )
     add_entrance_exam_milestone(self.course.id, created_block)
     content_milestones = milestones_helpers.get_course_content_milestones(
         unicode(self.course.id),
         unicode(created_block.location),
         self.milestone_relationship_types['FULFILLS']
     )
     self.assertEqual(len(content_milestones), 1)
     user = UserFactory()
     request = RequestFactory().request()
     request.user = user
     remove_entrance_exam_milestone_reference(request, self.course.id)
     content_milestones = milestones_helpers.get_course_content_milestones(
         unicode(self.course.id),
         unicode(created_block.location),
         self.milestone_relationship_types['FULFILLS']
     )
     self.assertEqual(len(content_milestones), 0)
开发者ID:cpennington,项目名称:edx-platform,代码行数:29,代码来源:test_entrance_exam.py

示例2: _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:
             # We don't have access to the true request object in this context, but we can use a mock
             request = RequestFactory().request()
             request.user = user
             exam_pct = get_entrance_exam_score(request, course)
             if exam_pct >= course.entrance_exam_minimum_score_pct:
                 exam_key = UsageKey.from_string(course.entrance_exam_id)
                 relationship_types = milestones_helpers.get_milestone_relationship_types()
                 content_milestones = milestones_helpers.get_course_content_milestones(
                     course_key,
                     exam_key,
                     relationship=relationship_types['FULFILLS']
                 )
                 # Add each milestone to the user's set...
                 user = {'id': request.user.id}
                 for milestone in content_milestones:
                     milestones_helpers.add_user_milestone(user, milestone)
开发者ID:Taxellool,项目名称:edx-platform,代码行数:29,代码来源:module_render.py

示例3: test_get_course_content_milestones_returns_none_when_app_disabled

 def test_get_course_content_milestones_returns_none_when_app_disabled(self):
     response = milestones_helpers.get_course_content_milestones(
         unicode(self.course.id),
         'i4x://doesnt/matter/for/this/test',
         'requires'
     )
     self.assertEqual(len(response), 0)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:7,代码来源:test_milestones_helpers.py

示例4: test_import_delete_pre_exiting_entrance_exam

    def test_import_delete_pre_exiting_entrance_exam(self):
        """
        Check that pre existed entrance exam content should be overwrite with the imported course.
        """
        exam_url = '/course/{}/entrance_exam/'.format(unicode(self.course.id))
        resp = self.client.post(exam_url, {'entrance_exam_minimum_score_pct': 0.5}, http_accept='application/json')
        self.assertEqual(resp.status_code, 201)

        # 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.assertEqual(metadata['entrance_exam_minimum_score_pct']['value'], 0.5)
        self.assertTrue(len(milestones_helpers.get_course_milestones(unicode(self.course.id))))
        content_milestones = milestones_helpers.get_course_content_milestones(
            unicode(self.course.id),
            metadata['entrance_exam_id']['value'],
            milestones_helpers.get_milestone_relationship_types()['FULFILLS']
        )
        self.assertTrue(len(content_milestones))

        # Now import entrance exam course
        with open(self.entrance_exam_tar) as gtar:
            args = {"name": self.entrance_exam_tar, "course-data": [gtar]}
            resp = self.client.post(self.url, args)
        self.assertEquals(resp.status_code, 200)
        course = self.store.get_course(self.course.id)
        self.assertIsNotNone(course)
        self.assertEquals(course.entrance_exam_enabled, True)
        self.assertEquals(course.entrance_exam_minimum_score_pct, 0.7)
开发者ID:cpennington,项目名称:edx-platform,代码行数:31,代码来源:test_import_export.py

示例5: evaluate_entrance_exam

def evaluate_entrance_exam(course, block, user_id):
    """
    Update 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 milestones_helpers.is_entrance_exams_enabled():
        entrance_exam_enabled = getattr(course, 'entrance_exam_enabled', False)
        in_entrance_exam = getattr(block, 'in_entrance_exam', False)
        if entrance_exam_enabled and in_entrance_exam:
            # We don't have access to the true request object in this context, but we can use a mock
            request = RequestFactory().request()
            request.user = User.objects.get(id=user_id)
            exam_pct = get_entrance_exam_score(request, course)
            if exam_pct >= course.entrance_exam_minimum_score_pct:
                exam_key = UsageKey.from_string(course.entrance_exam_id)
                relationship_types = milestones_helpers.get_milestone_relationship_types()
                content_milestones = milestones_helpers.get_course_content_milestones(
                    course.id,
                    exam_key,
                    relationship=relationship_types['FULFILLS']
                )
                # Add each milestone to the user's set...
                user = {'id': request.user.id}
                for milestone in content_milestones:
                    milestones_helpers.add_user_milestone(user, milestone)
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:27,代码来源:api.py

示例6: has_pending_milestones_for_user

 def has_pending_milestones_for_user(block_key, usage_info):
     """
     Test whether the current user has any unfulfilled milestones preventing
     them from accessing this block.
     """
     return bool(milestones_helpers.get_course_content_milestones(
         unicode(block_key.course_key),
         unicode(block_key),
         'requires',
         usage_info.user.id
     ))
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:11,代码来源:milestones.py

示例7: get_content_milestones_old

    def get_content_milestones_old(self, request, course_key):
        """
        Returns dict of subsections with prerequisites and whether the prerequisite has been completed or not
        """

        all_course_prereqs = get_course_content_milestones(course_key)

        content_ids_of_unfulfilled_prereqs = {
            milestone['content_id']
            for milestone in get_course_content_milestones(course_key, user_id=request.user.id)
        }

        course_content_milestones = {
            milestone['content_id']: {
                'completed_prereqs': milestone['content_id'] not in content_ids_of_unfulfilled_prereqs
            }
            for milestone in all_course_prereqs
        }

        return course_content_milestones
开发者ID:TeachAtTUM,项目名称:edx-platform,代码行数:20,代码来源:course_outline.py

示例8: compute_is_prereq_met

def compute_is_prereq_met(content_id, user_id, recalc_on_unmet=False):
    """
    Returns true if the prequiste has been met for a given milestone.
    Will recalculate the subsection grade if specified and prereq unmet

    Arguments:
        content_id (BlockUsageLocator): BlockUsageLocator for the content
        user_id: The id of the user
        recalc_on_unmet: Recalculate the grade if prereq has not yet been met

    Returns:
        tuple: True|False,
        prereq_meta_info = { 'url': prereq_url|None, 'display_name': prereq_name|None}
    """
    course_key = content_id.course_key

    # if unfullfilled milestones exist it means prereq has not been met
    unfulfilled_milestones = milestones_helpers.get_course_content_milestones(
        course_key,
        content_id,
        'requires',
        user_id
    )

    prereq_met = not unfulfilled_milestones
    prereq_meta_info = {'url': None, 'display_name': None}

    if prereq_met or not recalc_on_unmet:
        return prereq_met, prereq_meta_info

    milestone = unfulfilled_milestones[0]
    student = User.objects.get(id=user_id)
    store = modulestore()

    with store.bulk_operations(course_key):
        subsection_usage_key = UsageKey.from_string(_get_gating_block_id(milestone))
        subsection = store.get_item(subsection_usage_key)
        prereq_meta_info = {
            'url': reverse('jump_to', kwargs={'course_id': course_key, 'location': subsection_usage_key}),
            'display_name': subsection.display_name
        }

        try:
            subsection_structure = get_course_blocks(student, subsection_usage_key)
            if any(subsection_structure):
                subsection_grade_factory = SubsectionGradeFactory(student, course_structure=subsection_structure)
                if subsection_usage_key in subsection_structure:
                    # this will force a recalcuation of the subsection grade
                    subsection_grade = subsection_grade_factory.update(subsection_structure[subsection_usage_key], persist_grade=False)
                    prereq_met = update_milestone(milestone, subsection_grade, milestone, user_id)
        except ItemNotFoundError as err:
            log.warning("Could not find course_block for subsection=%s error=%s", subsection_usage_key, err)

    return prereq_met, prereq_meta_info
开发者ID:TeachAtTUM,项目名称:edx-platform,代码行数:54,代码来源:api.py

示例9: _can_access_descriptor_with_milestones

def _can_access_descriptor_with_milestones(user, descriptor, course_key):
    """
    Returns if the object is blocked by an unfulfilled milestone.

    Args:
        user: the user trying to access this content
        descriptor: the object being accessed
        course_key: key for the course for this descriptor
    """
    if milestones_helpers.get_course_content_milestones(course_key, unicode(descriptor.location), 'requires', user.id):
        debug("Deny: user has not completed all milestones for content")
        return ACCESS_DENIED
    else:
        return ACCESS_GRANTED
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:14,代码来源:access.py

示例10: get_content_milestones

    def get_content_milestones(self, request, course_key):
        """
        Returns dict of subsections with prerequisites and whether the prerequisite has been completed or not
        """
        def _get_key_of_prerequisite(namespace):
            return re.sub('.gating', '', namespace)

        all_course_milestones = get_course_content_milestones(course_key)

        uncompleted_prereqs = {
            milestone['content_id']
            for milestone in get_course_content_milestones(course_key, user_id=request.user.id)
        }

        gated_content = {
            milestone['content_id']: {
                'completed_prereqs': milestone['content_id'] not in uncompleted_prereqs,
                'prerequisite': _get_key_of_prerequisite(milestone['namespace'])
            }
            for milestone in all_course_milestones
        }

        return gated_content
开发者ID:mitocw,项目名称:edx-platform,代码行数:23,代码来源:course_outline.py

示例11: compute_is_prereq_met

def compute_is_prereq_met(content_id, user_id, recalc_on_unmet=False):
    """
    Returns true if the prequiste has been met for a given milestone.
    Will recalculate the subsection grade if specified and prereq unmet

    Arguments:
        content_id (BlockUsageLocator): BlockUsageLocator for the content
        user_id: The id of the user
        recalc_on_unmet: Recalculate the grade if prereq has not yet been met

    Returns:
        tuple: True|False,
        prereq_meta_info = { 'url': prereq_url|None, 'display_name': prereq_name|None}
    """
    course_key = content_id.course_key

    # if unfullfilled milestones exist it means prereq has not been met
    unfulfilled_milestones = milestones_helpers.get_course_content_milestones(
        course_key,
        content_id,
        'requires',
        user_id
    )

    prereq_met = not unfulfilled_milestones
    prereq_meta_info = {'url': None, 'display_name': None}

    if prereq_met or not recalc_on_unmet:
        return prereq_met, prereq_meta_info

    milestone = unfulfilled_milestones[0]
    student = User.objects.get(id=user_id)
    store = modulestore()

    with store.bulk_operations(course_key):
        subsection_usage_key = UsageKey.from_string(_get_gating_block_id(milestone))
        subsection = store.get_item(subsection_usage_key)
        prereq_meta_info = {
            'url': reverse('jump_to', kwargs={'course_id': course_key, 'location': subsection_usage_key}),
            'display_name': subsection.display_name
        }
        prereq_met = update_milestone(milestone, subsection_usage_key, milestone, student)

    return prereq_met, prereq_meta_info
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:44,代码来源:api.py

示例12: test_entrance_exam_milestone_addition

 def test_entrance_exam_milestone_addition(self):
     """
     Unit Test: test addition of entrance exam milestone content
     """
     parent_locator = unicode(self.course.location)
     created_block = create_xblock(
         parent_locator=parent_locator,
         user=self.user,
         category='chapter',
         display_name=('Entrance Exam'),
         is_entrance_exam=True
     )
     add_entrance_exam_milestone(self.course.id, created_block)
     content_milestones = milestones_helpers.get_course_content_milestones(
         unicode(self.course.id),
         unicode(created_block.location),
         self.milestone_relationship_types['FULFILLS']
     )
     self.assertTrue(len(content_milestones))
     self.assertEqual(len(milestones_helpers.get_course_milestones(self.course.id)), 1)
开发者ID:cpennington,项目名称:edx-platform,代码行数:20,代码来源:test_entrance_exam.py

示例13: evaluate_entrance_exam

def evaluate_entrance_exam(course_grade, user):
    """
    Evaluates any entrance exam milestone relationships attached
    to the given course. If the course_grade meets the
    minimum score required, the dependent milestones will be marked
    fulfilled for the user.
    """
    course = course_grade.course_data.course
    if milestones_helpers.is_entrance_exams_enabled() and getattr(course, 'entrance_exam_enabled', False):
        if get_entrance_exam_content(user, course):
            exam_chapter_key = get_entrance_exam_usage_key(course)
            exam_score_ratio = get_entrance_exam_score_ratio(course_grade, exam_chapter_key)
            if exam_score_ratio >= course.entrance_exam_minimum_score_pct:
                relationship_types = milestones_helpers.get_milestone_relationship_types()
                content_milestones = milestones_helpers.get_course_content_milestones(
                    course.id,
                    exam_chapter_key,
                    relationship=relationship_types['FULFILLS']
                )
                # Mark each entrance exam dependent milestone as fulfilled by the user.
                for milestone in content_milestones:
                    milestones_helpers.add_user_milestone({'id': user.id}, milestone)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:22,代码来源:api.py

示例14: 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_helpers.get_course_milestones(unicode(self.course.id))))
        content_milestones = milestones_helpers.get_course_content_milestones(
            unicode(self.course.id),
            metadata['entrance_exam_id']['value'],
            self.milestone_relationship_types['FULFILLS']
        )
        self.assertTrue(len(content_milestones))
开发者ID:cpennington,项目名称:edx-platform,代码行数:22,代码来源:test_entrance_exam.py


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