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


Python StaticContent.is_c4x_path方法代码示例

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


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

示例1: remap_namespace

# 需要导入模块: from xmodule.contentstore.content import StaticContent [as 别名]
# 或者: from xmodule.contentstore.content.StaticContent import is_c4x_path [as 别名]
def remap_namespace(module, target_location_namespace):
    if target_location_namespace is None:
        return module

    # This looks a bit wonky as we need to also change the 'name' of the
    # imported course to be what the caller passed in
    if module.location.category != 'course':
        module.location = module.location._replace(
            tag=target_location_namespace.tag,
            org=target_location_namespace.org,
            course=target_location_namespace.course
        )
    else:
        original_location = module.location
        #
        # module is a course module
        #
        module.location = module.location._replace(
            tag=target_location_namespace.tag,
            org=target_location_namespace.org,
            course=target_location_namespace.course,
            name=target_location_namespace.name
        )
        # There is more re-namespacing work we have to do when
        # importing course modules

        # remap pdf_textbook urls
        for entry in module.pdf_textbooks:
            for chapter in entry.get('chapters', []):
                if StaticContent.is_c4x_path(chapter.get('url', '')):
                    chapter['url'] = StaticContent.renamespace_c4x_path(
                        chapter['url'], target_location_namespace
                    )

        # if there is a wiki_slug which is the same as the original location
        # (aka default value), then remap that so the wiki doesn't point to
        # the old Wiki.
        if module.wiki_slug == original_location.course:
            module.wiki_slug = target_location_namespace.course

        module.save()

    # then remap children pointers since they too will be re-namespaced
    if hasattr(module, 'children'):
        children_locs = module.children
        if children_locs is not None and children_locs != []:
            new_locs = []
            for child in children_locs:
                child_loc = Location(child)
                new_child_loc = child_loc._replace(
                    tag=target_location_namespace.tag,
                    org=target_location_namespace.org,
                    course=target_location_namespace.course
                )

                new_locs.append(new_child_loc.url())

            module.children = new_locs

    return module
开发者ID:gmugando,项目名称:edx-platform,代码行数:62,代码来源:xml_importer.py

示例2: static_updater

# 需要导入模块: from xmodule.contentstore.content import StaticContent [as 别名]
# 或者: from xmodule.contentstore.content.StaticContent import is_c4x_path [as 别名]
    def static_updater(self, course, source_courselike, courselike_key, dest_id, runtime):
        """
        Update special static assets, such as PDF textbooks and wiki resources.
        """
        for entry in course.pdf_textbooks:
            for chapter in entry.get('chapters', []):
                if StaticContent.is_c4x_path(chapter.get('url', '')):
                    asset_key = StaticContent.get_location_from_path(chapter['url'])
                    chapter['url'] = StaticContent.get_static_path_from_location(asset_key)

        # Original wiki_slugs had value location.course. To make them unique this was changed to 'org.course.name'.
        # If we are importing into a course with a different course_id and wiki_slug is equal to either of these default
        # values then remap it so that the wiki does not point to the old wiki.
        if courselike_key != course.id:
            if self.xml_module_store.course_run is None:
                original_course_run = courselike_key.run
            else:
                original_course_run = self.xml_module_store.course_run

            original_unique_wiki_slug = u'{0}.{1}.{2}'.format(
                courselike_key.org,
                courselike_key.course,
                original_course_run,
            )
            if course.wiki_slug == original_unique_wiki_slug or course.wiki_slug == courselike_key.course:
                course.wiki_slug = u'{0}.{1}.{2}'.format(
                    course.id.org,
                    course.id.course,
                    course.id.run,
                )

        # cdodge: more hacks (what else). Seems like we have a
        # problem when importing a course (like 6.002) which
        # does not have any tabs defined in the policy file.
        # The import goes fine and then displays fine in LMS,
        # but if someone tries to add a new tab in the CMS, then
        # the LMS barfs because it expects that -- if there are
        # *any* tabs -- then there at least needs to be
        # some predefined ones
        if course.tabs is None or len(course.tabs) == 0:
            CourseTabList.initialize_default(course)
开发者ID:msaqib52,项目名称:edx-platform,代码行数:43,代码来源:xml_importer.py

示例3: remap_namespace

# 需要导入模块: from xmodule.contentstore.content import StaticContent [as 别名]
# 或者: from xmodule.contentstore.content.StaticContent import is_c4x_path [as 别名]
def remap_namespace(module, target_location_namespace):
    if target_location_namespace is None:
        return module

    original_location = module.location

    # This looks a bit wonky as we need to also change the 'name' of the
    # imported course to be what the caller passed in
    if module.location.category != 'course':
        _update_module_location(
            module,
            module.location.replace(
                tag=target_location_namespace.tag,
                org=target_location_namespace.org,
                course=target_location_namespace.course
            )
        )

    else:
        #
        # module is a course module
        #
        module.location = module.location.replace(
            tag=target_location_namespace.tag,
            org=target_location_namespace.org,
            course=target_location_namespace.course,
            name=target_location_namespace.name
        )
        # There is more re-namespacing work we have to do when
        # importing course modules

        # remap pdf_textbook urls to portable static URLs
        for entry in module.pdf_textbooks:
            for chapter in entry.get('chapters', []):
                if StaticContent.is_c4x_path(chapter.get('url', '')):
                    chapter_loc = StaticContent.get_location_from_path(chapter['url'])
                    chapter['url'] = StaticContent.get_static_path_from_location(
                        chapter_loc
                    )

        # Original wiki_slugs had value location.course. To make them unique this was changed to 'org.course.name'.
        # If we are importing into a course with a different course_id and wiki_slug is equal to either of these default
        # values then remap it so that the wiki does not point to the old wiki.
        if original_location.course_id != target_location_namespace.course_id:
            original_unique_wiki_slug = u'{0}.{1}.{2}'.format(
                original_location.org,
                original_location.course,
                original_location.name
            )
            if module.wiki_slug == original_unique_wiki_slug or module.wiki_slug == original_location.course:
                module.wiki_slug = u'{0}.{1}.{2}'.format(
                    target_location_namespace.org,
                    target_location_namespace.course,
                    target_location_namespace.name,
                )

        module.save()

    all_fields = module.get_explicitly_set_fields_by_scope(Scope.content)
    all_fields.update(module.get_explicitly_set_fields_by_scope(Scope.settings))
    if hasattr(module, 'children'):
        all_fields['children'] = module.children

    def convert_ref(reference):
        """
        Convert a reference to the new namespace, but only
        if the original namespace matched the original course.

        Otherwise, returns the input value.
        """
        new_ref = reference
        ref = Location(reference)
        in_original_namespace = (original_location.tag == ref.tag and
                                 original_location.org == ref.org and
                                 original_location.course == ref.course)
        if in_original_namespace:
            new_ref = ref.replace(
                tag=target_location_namespace.tag,
                org=target_location_namespace.org,
                course=target_location_namespace.course
            ).url()
        return new_ref

    for field_name in all_fields:
        field_object = module.fields.get(field_name)
        if isinstance(field_object, Reference):
            new_ref = convert_ref(getattr(module, field_name))
            setattr(module, field_name, new_ref)
            module.save()
        elif isinstance(field_object, ReferenceList):
            references = getattr(module, field_name)
            new_references = [convert_ref(reference) for reference in references]
            setattr(module, field_name, new_references)
            module.save()
        elif isinstance(field_object, ReferenceValueDict):
            reference_dict = getattr(module, field_name)
            new_reference_dict = {
                key: convert_ref(reference)
                for key, reference
                in reference_dict.items()
#.........这里部分代码省略.........
开发者ID:Jacksing,项目名称:edx-platform,代码行数:103,代码来源:xml_importer.py

示例4: _import_course_module

# 需要导入模块: from xmodule.contentstore.content import StaticContent [as 别名]
# 或者: from xmodule.contentstore.content.StaticContent import is_c4x_path [as 别名]
def _import_course_module(
        store, runtime, user_id, data_dir, course_key, dest_course_id, source_course, do_import_static,
        verbose,
):
    if verbose:
        log.debug("Scanning {0} for course module...".format(course_key))

    # Quick scan to get course module as we need some info from there.
    # Also we need to make sure that the course module is committed
    # first into the store
    course_data_path = path(data_dir) / source_course.data_dir

    log.debug(u'======> IMPORTING course {course_key}'.format(
        course_key=course_key,
    ))

    if not do_import_static:
        # for old-style xblock where this was actually linked to kvs
        source_course.static_asset_path = source_course.data_dir
        source_course.save()
        log.debug('course static_asset_path={path}'.format(
            path=source_course.static_asset_path
        ))

    log.debug('course data_dir={0}'.format(source_course.data_dir))

    with store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, dest_course_id):

        course = _import_module_and_update_references(
            source_course, store, user_id,
            course_key,
            dest_course_id,
            do_import_static=do_import_static,
            runtime=runtime,
        )

        for entry in course.pdf_textbooks:
            for chapter in entry.get('chapters', []):
                if StaticContent.is_c4x_path(chapter.get('url', '')):
                    asset_key = StaticContent.get_location_from_path(chapter['url'])
                    chapter['url'] = StaticContent.get_static_path_from_location(asset_key)

        # Original wiki_slugs had value location.course. To make them unique this was changed to 'org.course.name'.
        # If we are importing into a course with a different course_id and wiki_slug is equal to either of these default
        # values then remap it so that the wiki does not point to the old wiki.
        if course_key != course.id:
            original_unique_wiki_slug = u'{0}.{1}.{2}'.format(
                course_key.org,
                course_key.course,
                course_key.run
            )
            if course.wiki_slug == original_unique_wiki_slug or course.wiki_slug == course_key.course:
                course.wiki_slug = u'{0}.{1}.{2}'.format(
                    course.id.org,
                    course.id.course,
                    course.id.run,
                )

        # cdodge: more hacks (what else). Seems like we have a
        # problem when importing a course (like 6.002) which
        # does not have any tabs defined in the policy file.
        # The import goes fine and then displays fine in LMS,
        # but if someone tries to add a new tab in the CMS, then
        # the LMS barfs because it expects that -- if there are
        # *any* tabs -- then there at least needs to be
        # some predefined ones
        if course.tabs is None or len(course.tabs) == 0:
            CourseTabList.initialize_default(course)

        store.update_item(course, user_id)
    return course, course_data_path
开发者ID:IET-OU,项目名称:edx-platform,代码行数:73,代码来源:xml_importer.py

示例5: import_from_xml

# 需要导入模块: from xmodule.contentstore.content import StaticContent [as 别名]
# 或者: from xmodule.contentstore.content.StaticContent import is_c4x_path [as 别名]

#.........这里部分代码省略.........
                if verbose:
                    log.debug("Scanning {0} for course module...".format(course_key))

                # Quick scan to get course module as we need some info from there.
                # Also we need to make sure that the course module is committed
                # first into the store
                for module in xml_module_store.modules[course_key].itervalues():
                    if module.scope_ids.block_type == 'course':
                        course_data_path = path(data_dir) / module.data_dir

                        log.debug(u'======> IMPORTING course {course_key}'.format(
                            course_key=course_key,
                        ))

                        if not do_import_static:
                            # for old-style xblock where this was actually linked to kvs
                            module.static_asset_path = module.data_dir
                            module.save()
                            log.debug('course static_asset_path={path}'.format(
                                path=module.static_asset_path
                            ))

                        log.debug('course data_dir={0}'.format(module.data_dir))

                        course = _import_module_and_update_references(
                            module, store, user_id,
                            course_key,
                            dest_course_id,
                            do_import_static=do_import_static
                        )

                        for entry in course.pdf_textbooks:
                            for chapter in entry.get('chapters', []):
                                if StaticContent.is_c4x_path(chapter.get('url', '')):
                                    asset_key = StaticContent.get_location_from_path(chapter['url'])
                                    chapter['url'] = StaticContent.get_static_path_from_location(asset_key)

                        # Original wiki_slugs had value location.course. To make them unique this was changed to 'org.course.name'.
                        # If we are importing into a course with a different course_id and wiki_slug is equal to either of these default
                        # values then remap it so that the wiki does not point to the old wiki.
                        if course_key != course.id:
                            original_unique_wiki_slug = u'{0}.{1}.{2}'.format(
                                course_key.org,
                                course_key.course,
                                course_key.run
                            )
                            if course.wiki_slug == original_unique_wiki_slug or course.wiki_slug == course_key.course:
                                course.wiki_slug = u'{0}.{1}.{2}'.format(
                                    course.id.org,
                                    course.id.course,
                                    course.id.run,
                                )

                        # cdodge: more hacks (what else). Seems like we have a
                        # problem when importing a course (like 6.002) which
                        # does not have any tabs defined in the policy file.
                        # The import goes fine and then displays fine in LMS,
                        # but if someone tries to add a new tab in the CMS, then
                        # the LMS barfs because it expects that -- if there are
                        # *any* tabs -- then there at least needs to be
                        # some predefined ones
                        if course.tabs is None or len(course.tabs) == 0:
                            CourseTabList.initialize_default(course)

                        store.update_item(course, user_id)
开发者ID:karsibali,项目名称:edx-platform,代码行数:69,代码来源:xml_importer.py

示例6: remap_namespace

# 需要导入模块: from xmodule.contentstore.content import StaticContent [as 别名]
# 或者: from xmodule.contentstore.content.StaticContent import is_c4x_path [as 别名]
def remap_namespace(module, target_location_namespace):
    if target_location_namespace is None:
        return module

    original_location = module.location

    # This looks a bit wonky as we need to also change the 'name' of the
    # imported course to be what the caller passed in
    if module.location.category != 'course':
        module.location = module.location.replace(
            tag=target_location_namespace.tag,
            org=target_location_namespace.org,
            course=target_location_namespace.course
        )
    else:
        #
        # module is a course module
        #
        module.location = module.location.replace(
            tag=target_location_namespace.tag,
            org=target_location_namespace.org,
            course=target_location_namespace.course,
            name=target_location_namespace.name
        )
        # There is more re-namespacing work we have to do when
        # importing course modules

        # remap pdf_textbook urls
        for entry in module.pdf_textbooks:
            for chapter in entry.get('chapters', []):
                if StaticContent.is_c4x_path(chapter.get('url', '')):
                    chapter['url'] = StaticContent.renamespace_c4x_path(
                        chapter['url'], target_location_namespace
                    )

        # if there is a wiki_slug which is the same as the original location
        # (aka default value), then remap that so the wiki doesn't point to
        # the old Wiki.
        if module.wiki_slug == original_location.course:
            module.wiki_slug = target_location_namespace.course

        module.save()

    all_fields = module.get_explicitly_set_fields_by_scope(Scope.content)
    all_fields.update(module.get_explicitly_set_fields_by_scope(Scope.settings))
    if hasattr(module, 'children'):
        all_fields['children'] = module.children

    def convert_ref(reference):
        """
        Convert a reference to the new namespace, but only
        if the original namespace matched the original course.

        Otherwise, returns the input value.
        """
        new_ref = reference
        ref = Location(reference)
        in_original_namespace = (original_location.tag == ref.tag and
                                 original_location.org == ref.org and
                                 original_location.course == ref.course)
        if in_original_namespace:
            new_ref = ref.replace(
                tag=target_location_namespace.tag,
                org=target_location_namespace.org,
                course=target_location_namespace.course
            ).url()
        return new_ref

    for field in all_fields:
        if isinstance(module.fields.get(field), Reference):
            new_ref = convert_ref(getattr(module, field))
            setattr(module, field, new_ref)
            module.save()
        elif isinstance(module.fields.get(field), ReferenceList):
            references = getattr(module, field)
            new_references = [convert_ref(reference) for reference in references]
            setattr(module, field, new_references)
            module.save()

    return module
开发者ID:JamseSun,项目名称:edx-platform,代码行数:82,代码来源:xml_importer.py


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