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


Python search.path_to_location函数代码示例

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


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

示例1: does_location_exist

def does_location_exist(course_id, location):
    """
    Checks to see if a valid module exists at a given location (ie has not been deleted)
    course_id - string course id
    location - string location
    """
    try:
        search.path_to_location(modulestore(), course_id, location)
        return True
    except ItemNotFoundError:
        #If the problem cannot be found at the location received from the grading controller server, it has been deleted by the course author.
        return False
开发者ID:LukeLu1263,项目名称:edx-platform,代码行数:12,代码来源:utils.py

示例2: location

    def location(self):
        """
        Blend "location" property into the resultset, so that the path to the found component can be shown within the UI
        """
        # TODO: update whern changes to "cohorted-courseware" branch are merged in
        (course_key, chapter, section, position) = path_to_location(self.get_module_store(), self.get_usage_key())

        def get_display_name(item_key):
            """ gets display name from object's key """
            item = self.get_item(item_key)
            display_name = getattr(item, "display_name", None)
            return display_name if display_name else UNNAMED_MODULE_NAME

        def get_position_name(section, position):
            """ helper to fetch name corresponding to the position therein """
            pos = int(position)
            section_item = self.get_item(course_key.make_usage_key("sequential", section))
            if section_item.has_children and len(section_item.children) >= pos:
                return get_display_name(section_item.children[pos - 1])
            return None

        location_description = []
        if chapter:
            location_description.append(get_display_name(course_key.make_usage_key("chapter", chapter)))
        if section:
            location_description.append(get_display_name(course_key.make_usage_key("sequential", section)))
        if position:
            location_description.append(get_position_name(section, position))

        return location_description
开发者ID:mrgnr,项目名称:edx-platform,代码行数:30,代码来源:lms_result_processor.py

示例3: jump_to

def jump_to(request, course_id, location):
    """
    Show the page that contains a specific location.

    If the location is invalid or not in any class, return a 404.

    Otherwise, delegates to the index view to figure out whether this user
    has access, and what they should see.
    """
    try:
        course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
        usage_key = course_key.make_usage_key_from_deprecated_string(location)
    except InvalidKeyError:
        raise Http404(u"Invalid course_key or usage_key")
    try:
        (course_key, chapter, section, position) = path_to_location(modulestore(), usage_key)
    except ItemNotFoundError:
        raise Http404(u"No data at this location: {0}".format(usage_key))
    except NoPathToItem:
        raise Http404(u"This location is not in any class: {0}".format(usage_key))

    # choose the appropriate view (and provide the necessary args) based on the
    # args provided by the redirect.
    # Rely on index to do all error handling and access control.
    if chapter is None:
        return redirect('courseware', course_id=course_key.to_deprecated_string())
    elif section is None:
        return redirect('courseware_chapter', course_id=course_key.to_deprecated_string(), chapter=chapter)
    elif position is None:
        return redirect('courseware_section', course_id=course_key.to_deprecated_string(), chapter=chapter, section=section)
    else:
        return redirect('courseware_position', course_id=course_key.to_deprecated_string(), chapter=chapter, section=section, position=position)
开发者ID:BenjiLee,项目名称:edx-platform,代码行数:32,代码来源:views.py

示例4: find_peer_grading_module

def find_peer_grading_module(course):
    """
    Given a course, finds the first peer grading module in it.
    @param course: A course object.
    @return: boolean found_module, string problem_url
    """

    # Reverse the base course url.
    base_course_url = reverse("courses")
    found_module = False
    problem_url = ""

    # Get the peer grading modules currently in the course.  Explicitly specify the course id to avoid issues with different runs.
    items = modulestore().get_items(course.id, category="peergrading")
    # See if any of the modules are centralized modules (ie display info from multiple problems)
    items = [i for i in items if not getattr(i, "use_for_single_location", True)]
    # Loop through all potential peer grading modules, and find the first one that has a path to it.
    for item in items:
        # Generate a url for the first module and redirect the user to it.
        try:
            problem_url_parts = search.path_to_location(modulestore(), item.location)
        except NoPathToItem:
            # In the case of nopathtoitem, the peer grading module that was found is in an invalid state, and
            # can no longer be accessed.  Log an informational message, but this will not impact normal behavior.
            log.info(
                u"Invalid peer grading module location {0} in course {1}.  This module may need to be removed.".format(
                    item_location, course.id
                )
            )
            continue
        problem_url = generate_problem_url(problem_url_parts, base_course_url)
        found_module = True

    return found_module, problem_url
开发者ID:nanolearning,项目名称:edx-platform,代码行数:34,代码来源:views.py

示例5: find_peer_grading_module

def find_peer_grading_module(course):
    """
    Given a course, finds the first peer grading module in it.
    @param course: A course object.
    @return: boolean found_module, string problem_url
    """
    #Reverse the base course url
    base_course_url = reverse('courses')
    found_module = False
    problem_url = ""

    #Get the course id and split it
    course_id_parts = course.id.split("/")
    log.info("COURSE ID PARTS")
    log.info(course_id_parts)
    #Get the peer grading modules currently in the course.  Explicitly specify the course id to avoid issues with different runs.
    items = modulestore().get_items(['i4x', course_id_parts[0], course_id_parts[1], 'peergrading', None],
                                    course_id=course.id)
    #See if any of the modules are centralized modules (ie display info from multiple problems)
    items = [i for i in items if not getattr(i, "use_for_single_location", True)]
    #Get the first one
    if len(items) > 0:
        item_location = items[0].location
        #Generate a url for the first module and redirect the user to it
        problem_url_parts = search.path_to_location(modulestore(), course.id, item_location)
        problem_url = generate_problem_url(problem_url_parts, base_course_url)
        found_module = True

    return found_module, problem_url
开发者ID:Fyre91,项目名称:edx-platform,代码行数:29,代码来源:views.py

示例6: jump_to

def jump_to(request, course_id, location):
    """
    Show the page that contains a specific location.

    If the location is invalid or not in any class, return a 404.

    Otherwise, delegates to the index view to figure out whether this user
    has access, and what they should see.
    """
    # Complain if the location isn't valid
    try:
        location = Location(location)
    except InvalidLocationError:
        raise Http404("Invalid location")

    # Complain if there's not data for this location
    try:
        (course_id, chapter, section, position) = path_to_location(modulestore(), course_id, location)
    except ItemNotFoundError:
        raise Http404("No data at this location: {0}".format(location))
    except NoPathToItem:
        raise Http404("This location is not in any class: {0}".format(location))

    # choose the appropriate view (and provide the necessary args) based on the
    # args provided by the redirect.
    # Rely on index to do all error handling and access control.
    if chapter is None:
        return redirect("courseware", course_id=course_id)
    elif section is None:
        return redirect("courseware_chapter", course_id=course_id, chapter=chapter)
    elif position is None:
        return redirect("courseware_section", course_id=course_id, chapter=chapter, section=section)
    else:
        return redirect("courseware_position", course_id=course_id, chapter=chapter, section=section, position=position)
开发者ID:nikileshsa,项目名称:edx-platform,代码行数:34,代码来源:views.py

示例7: add_problem_data

    def add_problem_data(self, base_course_url):
        """
        Add metadata to problems.
        @param base_course_url: the base url for any course.  Can get with reverse('course')
        @return: A list of valid problems in the course and their appended data.
        """
        # Our list of valid problems.
        valid_problems = []

        if not self.success or not isinstance(self.problem_list, list):
            log.error("Called add_problem_data without a valid problem list" + self.course_error_ending)
            return valid_problems

        # Iterate through all of our problems and add data.
        for problem in self.problem_list:
            try:
                # Try to load the problem.
                problem_url_parts = search.path_to_location(modulestore(), self.course_id, problem['location'])
            except (ItemNotFoundError, NoPathToItem):
                # If the problem cannot be found at the location received from the grading controller server,
                # it has been deleted by the course author. We should not display it.
                error_message = "Could not find module for course {0} at location {1}".format(self.course_id,
                                                                                              problem['location'])
                log.error(error_message)
                continue

            # Get the problem url in the courseware.
            problem_url = generate_problem_url(problem_url_parts, base_course_url)

            # Map the grader name from ORA to a human readable version.
            grader_type_display_name = GRADER_DISPLAY_NAMES.get(problem['grader_type'], "edX Assessment")
            problem['actual_url'] = problem_url
            problem['grader_type_display_name'] = grader_type_display_name
            valid_problems.append(problem)
        return valid_problems
开发者ID:6thfdwp,项目名称:edx-platform,代码行数:35,代码来源:utils.py

示例8: test_path_to_location_for_orphan_chapter

    def test_path_to_location_for_orphan_chapter(self, module_store):
        r"""
        Make sure that path_to_location works with a component having multiple chapter parents,
        from which one of them is orphan

         course
            |
        chapter   chapter
           |         |
        vertical  vertical
              \    /
               html

        """
        # Get a course with orphan modules
        course = self.create_course_with_orphans(module_store)
        orphan_chapter = self.store.get_item(BlockUsageLocator(course.id, 'chapter', 'OrphanChapter'))
        chapter1 = self.store.get_item(BlockUsageLocator(course.id, 'chapter', 'Chapter1'))
        vertical1 = self.store.get_item(BlockUsageLocator(course.id, 'vertical', 'Vertical1'))

        # Verify `OrhanChapter` is an orphan
        self.assertIn(orphan_chapter.location, self.store.get_orphans(course.id))

        # Create a vertical (`Vertical0`) in orphan chapter (`OrphanChapter`).
        # OrphanChapter -> Vertical0
        vertical0 = self.store.create_child(self.user.id, orphan_chapter.location, 'vertical', "Vertical0")
        self.store.publish(vertical0.location, self.user.id)

        # Create a component in `Vertical0`
        # OrphanChapter -> Vertical0 -> Html
        html = self.store.create_child(self.user.id, vertical0.location, 'html', "HTML0")
        self.store.publish(html.location, self.user.id)

        # Verify chapter1 is parent of vertical1.
        vertical1_parent = self.store.get_parent_location(vertical1.location)
        self.assertEqual(unicode(vertical1_parent), unicode(chapter1.location))

        # Make `Vertical1` the parent of `HTML0`. So `HTML0` will have to parents (`Vertical0` & `Vertical1`)
        vertical1.children.append(html.location)
        self.store.update_item(vertical1, self.user.id)

        # Get parent location & verify its either of the two verticals. As both parents are non-orphan,
        # alphabetically least is returned
        html_parent = self.store.get_parent_location(html.location)
        self.assertEquals(unicode(html_parent), unicode(vertical1.location))

        # verify path_to_location returns a expected path
        path = path_to_location(self.store, html.location)
        expected_path = (
            course.id,
            chapter1.location.block_id,
            vertical1.location.block_id,
            html.location.block_id,
            "",
            path[-1]
        )
        self.assertIsNotNone(path)
        self.assertEqual(len(path), 6)
        self.assertEqual(path, expected_path)
开发者ID:shevious,项目名称:edx-platform,代码行数:59,代码来源:test_orphan.py

示例9: does_location_exist

def does_location_exist(usage_key):
    """
    Checks to see if a valid module exists at a given location (ie has not been deleted)
    course_id - string course id
    location - string location
    """
    try:
        search.path_to_location(modulestore(), usage_key)
        return True
    except ItemNotFoundError:
        # If the problem cannot be found at the location received from the grading controller server,
        # it has been deleted by the course author.
        return False
    except NoPathToItem:
        # If the problem can be found, but there is no path to it, then we assume it is a draft.
        # Log a warning in any case.
        log.warn("Got an unexpected NoPathToItem error in staff grading with location %s. "
                 "This is ok if it is a draft; ensure that the location is valid.", usage_key)
        return False
开发者ID:189140879,项目名称:edx-platform,代码行数:19,代码来源:utils.py

示例10: does_location_exist

def does_location_exist(course_id, location):
    """
    Checks to see if a valid module exists at a given location (ie has not been deleted)
    course_id - string course id
    location - string location
    """
    try:
        search.path_to_location(modulestore(), course_id, location)
        return True
    except ItemNotFoundError:
        # If the problem cannot be found at the location received from the grading controller server,
        # it has been deleted by the course author.
        return False
    except NoPathToItem:
        # If the problem can be found, but there is no path to it, then we assume it is a draft.
        # Log a warning if the problem is not a draft (location does not end in "draft").
        if not location.endswith("draft"):
            log.warn(("Got an unexpected NoPathToItem error in staff grading with a non-draft location {0}. "
                      "Ensure that the location is valid.").format(location))
        return False
开发者ID:AzizYosofi,项目名称:edx-platform,代码行数:20,代码来源:utils.py

示例11: check_path_to_location

def check_path_to_location(modulestore):
    """
    Make sure that path_to_location works: should be passed a modulestore
    with the toy and simple courses loaded.
    """
    course_id = SlashSeparatedCourseKey("edX", "toy", "2012_Fall")

    should_work = (
        (course_id.make_usage_key('video', 'Welcome'),
         (course_id, "Overview", "Welcome", None)),
        (course_id.make_usage_key('chapter', 'Overview'),
         (course_id, "Overview", None, None)),
    )

    for location, expected in should_work:
        assert_equals(path_to_location(modulestore, location), expected)

    not_found = (
        course_id.make_usage_key('video', 'WelcomeX'),
        course_id.make_usage_key('course', 'NotHome'),
    )
    for location in not_found:
        with assert_raises(ItemNotFoundError):
            path_to_location(modulestore, location)
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:24,代码来源:test_modulestore.py

示例12: get_redirect_url

def get_redirect_url(course_key, usage_key, child=None):
    """ Returns the redirect url back to courseware

    Args:
        course_id(str): Course Id string
        location(str): The location id of course component
        child(str): Optional child parameter to pass to the URL

    Raises:
        ItemNotFoundError if no data at the location or NoPathToItem if location not in any class

    Returns:
        Redirect url string
    """

    (
        course_key, chapter, section, vertical_unused,
        position, final_target_id
    ) = path_to_location(modulestore(), usage_key)

    # choose the appropriate view (and provide the necessary args) based on the
    # args provided by the redirect.
    # Rely on index to do all error handling and access control.
    if chapter is None:
        redirect_url = reverse('courseware', args=(unicode(course_key), ))
    elif section is None:
        redirect_url = reverse('courseware_chapter', args=(unicode(course_key), chapter))
    elif position is None:
        redirect_url = reverse(
            'courseware_section',
            args=(unicode(course_key), chapter, section)
        )
    else:
        # Here we use the navigation_index from the position returned from
        # path_to_location - we can only navigate to the topmost vertical at the
        # moment

        redirect_url = reverse(
            'courseware_position',
            args=(unicode(course_key), chapter, section, navigation_index(position))
        )

    redirect_url += "?{}".format(urlencode({'activate_block_id': unicode(final_target_id)}))

    if child:
        redirect_url += "&child={}".format(child)

    return redirect_url
开发者ID:Akif-Vohra,项目名称:edx-platform,代码行数:48,代码来源:url_helpers.py

示例13: test_path_to_location_for_orphan_vertical

    def test_path_to_location_for_orphan_vertical(self, module_store):
        r"""
        Make sure that path_to_location works with a component having multiple vertical parents,
        from which one of them is orphan.

         course
            |
         chapter
           |
         vertical vertical
            \     /
              html
        """
        # Get a course with orphan modules
        course = self.create_course_with_orphans(module_store)

        # Fetch the required course components.
        vertical1 = self.store.get_item(BlockUsageLocator(course.id, 'vertical', 'Vertical1'))
        chapter1 = self.store.get_item(BlockUsageLocator(course.id, 'chapter', 'Chapter1'))
        orphan_vertical = self.store.get_item(BlockUsageLocator(course.id, 'vertical', 'OrphanVert'))
        multi_parent_html = self.store.get_item(BlockUsageLocator(course.id, 'html', 'multi_parent_html'))

        # Verify `OrphanVert` is an orphan
        self.assertIn(orphan_vertical.location, self.store.get_orphans(course.id))

        # Verify `multi_parent_html` is child of both `Vertical1` and `OrphanVert`
        self.assertIn(multi_parent_html.location, orphan_vertical.children)
        self.assertIn(multi_parent_html.location, vertical1.children)

        # HTML component has `vertical1` as its parent.
        html_parent = self.store.get_parent_location(multi_parent_html.location)
        self.assertNotEqual(unicode(html_parent), unicode(orphan_vertical.location))
        self.assertEqual(unicode(html_parent), unicode(vertical1.location))

        # Get path of the `multi_parent_html` & verify path_to_location returns a expected path
        path = path_to_location(self.store, multi_parent_html.location)
        expected_path = (
            course.id,
            chapter1.location.block_id,
            vertical1.location.block_id,
            multi_parent_html.location.block_id,
            "",
            path[-1]
        )
        self.assertIsNotNone(path)
        self.assertEqual(len(path), 6)
        self.assertEqual(path, expected_path)
开发者ID:shevious,项目名称:edx-platform,代码行数:47,代码来源:test_orphan.py

示例14: check_path_to_location

def check_path_to_location(modulestore):
    '''Make sure that path_to_location works: should be passed a modulestore
    with the toy and simple courses loaded.'''
    should_work = (
        ("i4x://edX/toy/video/Welcome",
         ("edX/toy/2012_Fall", "Overview", "Welcome", None)),
        ("i4x://edX/toy/chapter/Overview",
         ("edX/toy/2012_Fall", "Overview", None, None)),
    )
    course_id = "edX/toy/2012_Fall"

    for location, expected in should_work:
        assert_equals(path_to_location(modulestore, course_id, location), expected)

    not_found = (
        "i4x://edX/toy/video/WelcomeX", "i4x://edX/toy/course/NotHome"
    )
    for location in not_found:
        assert_raises(ItemNotFoundError, path_to_location, modulestore, course_id, location)
开发者ID:Fyre91,项目名称:edx-platform,代码行数:19,代码来源:test_modulestore.py

示例15: get_path

    def get_path(usage_key):
        """
        Returns data for the path to the block in the course graph.

        Note: In case of multiple paths to the block from the course
        root, this function returns a path arbitrarily but consistently,
        depending on the modulestore. In the future, we may want to
        extend it to check which of the paths, the user has access to
        and return its data.

        Arguments:
            block (XBlock): The block whose path is required.

        Returns:
            list of PathItems
        """
        with modulestore().bulk_operations(usage_key.course_key):
            try:
                path = search.path_to_location(modulestore(), usage_key, full_path=True)
            except ItemNotFoundError:
                log.error(u'Block with usage_key: %s not found.', usage_key)
                return []
            except NoPathToItem:
                log.error(u'No path to block with usage_key: %s.', usage_key)
                return []

            path_data = []
            for ancestor_usage_key in path:
                if ancestor_usage_key != usage_key and ancestor_usage_key.block_type != 'course':  # pylint: disable=no-member
                    try:
                        block = modulestore().get_item(ancestor_usage_key)
                    except ItemNotFoundError:
                        return []  # No valid path can be found.

                    path_data.append(
                        PathItem(usage_key=block.location, display_name=block.display_name)
                    )

        return path_data
开发者ID:defance,项目名称:edx-platform,代码行数:39,代码来源:models.py


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