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


Python AssetLocation.from_string方法代码示例

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


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

示例1: copy_all_course_assets

# 需要导入模块: from opaque_keys.edx.locations import AssetLocation [as 别名]
# 或者: from opaque_keys.edx.locations.AssetLocation import from_string [as 别名]
    def copy_all_course_assets(self, source_course_key, dest_course_key):
        """
        See :meth:`.ContentStore.copy_all_course_assets`

        This implementation fairly expensively copies all of the data
        """
        source_query = query_for_course(source_course_key)
        # it'd be great to figure out how to do all of this on the db server and not pull the bits over
        for asset in self.fs_files.find(source_query):
            asset_key = self.make_id_son(asset)
            # don't convert from string until fs access
            source_content = self.fs.get(asset_key)
            if isinstance(asset_key, basestring):
                asset_key = AssetLocation.from_string(asset_key)
                __, asset_key = self.asset_db_key(asset_key)
            asset_key['org'] = dest_course_key.org
            asset_key['course'] = dest_course_key.course
            if getattr(dest_course_key, 'deprecated', False):  # remove the run if exists
                if 'run' in asset_key:
                    del asset_key['run']
                asset_id = asset_key
            else:  # add the run, since it's the last field, we're golden
                asset_key['run'] = dest_course_key.run
                asset_id = unicode(dest_course_key.make_asset_key(asset_key['category'], asset_key['name']))

            self.fs.put(
                source_content.read(),
                _id=asset_id, filename=asset['filename'], content_type=asset['contentType'],
                displayname=asset['displayname'], content_son=asset_key,
                # thumbnail is not technically correct but will be functionally correct as the code
                # only looks at the name which is not course relative.
                thumbnail_location=asset['thumbnail_location'],
                import_path=asset['import_path'],
                # getattr b/c caching may mean some pickled instances don't have attr
                locked=asset.get('locked', False)
            )
开发者ID:ibrahima,项目名称:edx-platform,代码行数:38,代码来源:mongo.py


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