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


Python Location.ensure_fully_specified方法代码示例

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


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

示例1: get_items

# 需要导入模块: from xmodule.modulestore import Location [as 别名]
# 或者: from xmodule.modulestore.Location import ensure_fully_specified [as 别名]
    def get_items(self, location, course_id=None, depth=0, qualifiers=None):
        """
        Returns a list of XModuleDescriptor instances for the items
        that match location. Any element of location that is None is treated
        as a wildcard that matches any value. NOTE: don't use this to look for courses
        as the course_id is required. Use get_courses.

        location: either a Location possibly w/ None as wildcards for category or name or
        a Locator with at least a package_id and branch but possibly no block_id.

        depth: An argument that some module stores may use to prefetch
            descendents of the queried modules for more efficient results later
            in the request. The depth is counted in the number of calls to
            get_children() to cache. None indicates to cache all descendents
        """
        if not (course_id or hasattr(location, 'package_id')):
            raise Exception("Must pass in a course_id when calling get_items()")

        store = self._get_modulestore_for_courseid(course_id or getattr(location, 'package_id'))
        # translate won't work w/ missing fields so work around it
        if store.reference_type == Location:
            if not self.use_locations:
                if getattr(location, 'block_id', False):
                    location = self._incoming_reference_adaptor(store, course_id, location)
                else:
                    # get the course's location
                    location = loc_mapper().translate_locator_to_location(location, get_course=True)
                    # now remove the unknowns
                    location = location.replace(
                        category=qualifiers.get('category', None),
                        name=None
                    )
        else:
            if self.use_locations:
                if not isinstance(location, Location):
                    location = Location(location)
                try:
                    location.ensure_fully_specified()
                    location = loc_mapper().translate_location(
                        course_id, location, location.revision == 'published', True
                    )
                except InsufficientSpecificationError:
                    # construct the Locator by hand
                    if location.category is not None and qualifiers.get('category', False):
                        qualifiers['category'] = location.category
                    location = loc_mapper().translate_location_to_course_locator(
                        course_id, location, location.revision == 'published'
                    )
        xblocks = store.get_items(location, course_id, depth, qualifiers)
        xblocks = [self._outgoing_xblock_adaptor(store, course_id, xblock) for xblock in xblocks]
        return xblocks
开发者ID:Caesar73,项目名称:edx-platform,代码行数:53,代码来源:mixed.py

示例2: get_parent_locations

# 需要导入模块: from xmodule.modulestore import Location [as 别名]
# 或者: from xmodule.modulestore.Location import ensure_fully_specified [as 别名]
 def get_parent_locations(self, location, course_id):
     """Find all locations that are the parents of this location in this
     course.  Needed for path_to_location().
     """
     location = Location.ensure_fully_specified(location)
     items = self.collection.find({"definition.children": location.url()}, {"_id": True})
     return [i["_id"] for i in items]
开发者ID:helanhe,项目名称:edx-platform,代码行数:9,代码来源:base.py

示例3: get_parent_locations

# 需要导入模块: from xmodule.modulestore import Location [as 别名]
# 或者: from xmodule.modulestore.Location import ensure_fully_specified [as 别名]
 def get_parent_locations(self, location, course_id):
     '''Find all locations that are the parents of this location in this
     course.  Needed for path_to_location().
     '''
     location = Location.ensure_fully_specified(location)
     items = self.collection.find({'definition.children': location.url()},
                                  {'_id': True})
     return [Location(i['_id']) for i in items]
开发者ID:WEForum,项目名称:edx-platform,代码行数:10,代码来源:base.py

示例4: has_item

# 需要导入模块: from xmodule.modulestore import Location [as 别名]
# 或者: from xmodule.modulestore.Location import ensure_fully_specified [as 别名]
 def has_item(self, course_id, location):
     """
     Returns True if location exists in this ModuleStore.
     """
     location = Location.ensure_fully_specified(location)
     try:
         self._find_one(location)
         return True
     except ItemNotFoundError:
         return False
开发者ID:WEForum,项目名称:edx-platform,代码行数:12,代码来源:base.py

示例5: set_attrs

# 需要导入模块: from xmodule.modulestore import Location [as 别名]
# 或者: from xmodule.modulestore.Location import ensure_fully_specified [as 别名]
    def set_attrs(self, location, attr_dict):
        """
        Like set_attr but sets multiple key value pairs.

        Returns nothing.

        Raises NotFoundError if no such item exists
        Raises AttributeError is attr_dict has any attrs which are one of the build in attrs.

        :param location:  a c4x asset location
        """
        # raises exception if location is not fully specified
        Location.ensure_fully_specified(location)
        for attr in attr_dict.iterkeys():
            if attr in ['_id', 'md5', 'uploadDate', 'length']:
                raise AttributeError("{} is a protected attribute.".format(attr))
        item = self.fs_files.find_one(location_to_query(location))
        if item is None:
            raise NotFoundError()
        self.fs_files.update({"_id": item["_id"]}, {"$set": attr_dict})
开发者ID:XiaodunServerGroup,项目名称:ddyedx,代码行数:22,代码来源:mongo.py

示例6: get_instance_items

# 需要导入模块: from xmodule.modulestore import Location [as 别名]
# 或者: from xmodule.modulestore.Location import ensure_fully_specified [as 别名]
 def get_instance_items(self, course_id, location, category, depth=0):
     """
     Return an array all of the locations for orphans in the course.
     """
     '''
     all_items = self.collection.find({
         '_id.org': location.org,
         '_id.course': location.course,
         #'_id.category': {'$nin': detached_categories}
     })
     '''
     location = Location.ensure_fully_specified(location)
     item = self._find_one(location)
     module = self._load_items_category([item], category, course_id, depth)[1]
     return module
开发者ID:EduPepperPD,项目名称:pepper2013,代码行数:17,代码来源:base.py

示例7: get_item

# 需要导入模块: from xmodule.modulestore import Location [as 别名]
# 或者: from xmodule.modulestore.Location import ensure_fully_specified [as 别名]
    def get_item(self, location, depth=0):
        """
        Returns an XModuleDescriptor instance for the item at location.

        If any segment of the location is None except revision, raises
            xmodule.modulestore.exceptions.InsufficientSpecificationError
        If no object is found at that location, raises
            xmodule.modulestore.exceptions.ItemNotFoundError

        location: a Location object
        depth (int): An argument that some module stores may use to prefetch
            descendents of the queried modules for more efficient results later
            in the request. The depth is counted in the number of
            calls to get_children() to cache. None indicates to cache all descendents.
        """
        location = Location.ensure_fully_specified(location)
        item = self._find_one(location)
        module = self._load_items([item], depth)[0]
        return module
开发者ID:WEForum,项目名称:edx-platform,代码行数:21,代码来源:base.py


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