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


Python static_replace.replace_static_urls函数代码示例

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


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

示例1: test_multi_replace

def test_multi_replace():
    course_source = '"/course/file.png"'

    assert replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY) == \
        replace_static_urls(replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY), DATA_DIRECTORY)
    assert replace_course_urls(course_source, COURSE_KEY) == \
        replace_course_urls(replace_course_urls(course_source, COURSE_KEY), COURSE_KEY)
开发者ID:cpennington,项目名称:edx-platform,代码行数:7,代码来源:test_static_replace.py

示例2: test_data_dir_fallback

def test_data_dir_fallback(mock_storage, mock_modulestore, mock_settings):
    mock_modulestore.return_value = Mock(XMLModuleStore)
    mock_storage.url.side_effect = Exception

    mock_storage.exists.return_value = True
    assert_equals('"/static/data_dir/file.png"', replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY))

    mock_storage.exists.return_value = False
    assert_equals('"/static/data_dir/file.png"', replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY))
开发者ID:Certific-NET,项目名称:edx-platform,代码行数:9,代码来源:test_static_replace.py

示例3: test_raw_static_check

def test_raw_static_check():
    """
    Make sure replace_static_urls leaves alone things that end in '.raw'
    """
    path = '"/static/foo.png?raw"'
    assert_equals(path, replace_static_urls(path, DATA_DIRECTORY))

    text = 'text <tag a="/static/js/capa/protex/protex.nocache.js?raw"/><div class="'
    assert_equals(path, replace_static_urls(path, text))
开发者ID:Certific-NET,项目名称:edx-platform,代码行数:9,代码来源:test_static_replace.py

示例4: test_multi_replace

def test_multi_replace():
    course_source = '"/course/file.png"'

    assert_equals(
        replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY),
        replace_static_urls(replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY), DATA_DIRECTORY)
    )
    assert_equals(
        replace_course_urls(course_source, course_id),
        replace_course_urls(replace_course_urls(course_source, course_id), course_id)
    )
开发者ID:pelikanchik,项目名称:edx-platform,代码行数:11,代码来源:test_static_replace.py

示例5: test_mongo_filestore

def test_mongo_filestore(mock_modulestore, mock_static_content):

    mock_modulestore.return_value = Mock(MongoModuleStore)
    mock_static_content.convert_legacy_static_url_with_course_id.return_value = "c4x://mock_url"

    # No namespace => no change to path
    assert_equals('"/static/data_dir/file.png"', replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY))

    # Namespace => content url
    assert_equals(
        '"' + mock_static_content.convert_legacy_static_url_with_course_id.return_value + '"',
        replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY, course_id=COURSE_KEY)
    )

    mock_static_content.convert_legacy_static_url_with_course_id.assert_called_once_with('file.png', COURSE_KEY)
开发者ID:Certific-NET,项目名称:edx-platform,代码行数:15,代码来源:test_static_replace.py

示例6: test_mongo_filestore

def test_mongo_filestore(mock_get_excluded_extensions, mock_get_base_url, mock_modulestore, mock_static_content):

    mock_modulestore.return_value = Mock(MongoModuleStore)
    mock_static_content.get_canonicalized_asset_path.return_value = "c4x://mock_url"
    mock_get_base_url.return_value = u''
    mock_get_excluded_extensions.return_value = ['foobar']

    # No namespace => no change to path
    assert replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY) == '"/static/data_dir/file.png"'

    # Namespace => content url
    assert '"' + mock_static_content.get_canonicalized_asset_path.return_value + '"' == \
        replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY, course_id=COURSE_KEY)

    mock_static_content.get_canonicalized_asset_path.assert_called_once_with(COURSE_KEY, 'file.png', u'', ['foobar'])
开发者ID:cpennington,项目名称:edx-platform,代码行数:15,代码来源:test_static_replace.py

示例7: test_storage_url_exists

def test_storage_url_exists(mock_storage):
    mock_storage.exists.return_value = True
    mock_storage.url.return_value = '/static/file.png'

    assert replace_static_urls(STATIC_SOURCE, DATA_DIRECTORY) == '"/static/file.png"'
    mock_storage.exists.assert_called_once_with('file.png')
    mock_storage.url.assert_called_once_with('file.png')
开发者ID:cpennington,项目名称:edx-platform,代码行数:7,代码来源:test_static_replace.py

示例8: get_module_info

def get_module_info(store, location, rewrite_static_links=False):
    try:
        module = store.get_item(location)
    except ItemNotFoundError:
        # create a new one
        store.create_and_save_xmodule(location)
        module = store.get_item(location)

    data = module.data
    if rewrite_static_links:
        # we pass a partially bogus course_id as we don't have the RUN information passed yet
        # through the CMS. Also the contentstore is also not RUN-aware at this point in time.
        data = replace_static_urls(
            module.data,
            None,
            course_id=module.location.org + '/' + module.location.course + '/BOGUS_RUN_REPLACE_WHEN_AVAILABLE'
        )

    return {
        'id': module.location.url(),
        'data': data,
        # TODO (cpennington): This really shouldn't have to do this much reaching in to get the metadata
        # what's the intent here? all metadata incl inherited & namespaced?
        'metadata': module.xblock_kvs._metadata
    }
开发者ID:AzizYosofi,项目名称:edx-platform,代码行数:25,代码来源:module_info_model.py

示例9: get_course_syllabus_section

def get_course_syllabus_section(course, section_key):
    """
    This returns the snippet of html to be rendered on the syllabus page,
    given the key for the section.

    Valid keys:
    - syllabus
    - guest_syllabus
    """

    # Many of these are stored as html files instead of some semantic
    # markup. This can change without effecting this interface when we find a
    # good format for defining so many snippets of text/html.

    if section_key in ['syllabus', 'guest_syllabus']:
        try:
            filesys = course.system.resources_fs
            # first look for a run-specific version
            dirs = [path("syllabus") / course.url_name, path("syllabus")]
            filepath = find_file(filesys, dirs, section_key + ".html")
            with filesys.open(filepath) as html_file:
                return replace_static_urls(
                    html_file.read().decode('utf-8'),
                    getattr(course, 'data_dir', None),
                    course_id=course.id,
                    static_asset_path=course.static_asset_path,
                )
        except ResourceNotFoundError:
            log.exception(
                u"Missing syllabus section %s in course %s",
                section_key, course.location.to_deprecated_string()
            )
            return "! Syllabus missing !"

    raise KeyError("Invalid about key " + str(section_key))
开发者ID:caseylitton,项目名称:edx-platform,代码行数:35,代码来源:courses.py

示例10: _get_module_info

def _get_module_info(usage_loc, rewrite_static_links=True):
    """
    metadata, data, id representation of a leaf module fetcher.
    :param usage_loc: A BlockUsageLocator
    """
    old_location = loc_mapper().translate_locator_to_location(usage_loc)
    store = get_modulestore(old_location)
    try:
        module = store.get_item(old_location)
    except ItemNotFoundError:
        if old_location.category in CREATE_IF_NOT_FOUND:
            # Create a new one for certain categories only. Used for course info handouts.
            store.create_and_save_xmodule(old_location)
            module = store.get_item(old_location)
        else:
            raise

    data = getattr(module, 'data', '')
    if rewrite_static_links:
        # we pass a partially bogus course_id as we don't have the RUN information passed yet
        # through the CMS. Also the contentstore is also not RUN-aware at this point in time.
        data = replace_static_urls(
            data,
            None,
            course_id=module.location.org + '/' + module.location.course + '/BOGUS_RUN_REPLACE_WHEN_AVAILABLE'
        )

    # Note that children aren't being returned until we have a use case.
    return {
        'id': unicode(usage_loc),
        'data': data,
        'metadata': own_metadata(module)
    }
开发者ID:BeiLuoShiMen,项目名称:edx-platform,代码行数:33,代码来源:item.py

示例11: _get_module_info

def _get_module_info(xblock, rewrite_static_links=True, include_ancestor_info=False, include_publishing_info=False):
    """
    metadata, data, id representation of a leaf module fetcher.
    :param usage_key: A UsageKey
    """
    with modulestore().bulk_operations(xblock.location.course_key):
        data = getattr(xblock, 'data', '')
        if rewrite_static_links:
            data = replace_static_urls(
                data,
                None,
                course_id=xblock.location.course_key
            )

        # Pre-cache has changes for the entire course because we'll need it for the ancestor info
        # Except library blocks which don't [yet] use draft/publish
        if not isinstance(xblock.location, LibraryUsageLocator):
            modulestore().has_changes(modulestore().get_course(xblock.location.course_key, depth=None))

        # Note that children aren't being returned until we have a use case.
        xblock_info = create_xblock_info(
            xblock, data=data, metadata=own_metadata(xblock), include_ancestor_info=include_ancestor_info
        )
        if include_publishing_info:
            add_container_page_publishing_info(xblock, xblock_info)
        return xblock_info
开发者ID:189140879,项目名称:edx-platform,代码行数:26,代码来源:item.py

示例12: _get_module_info

def _get_module_info(usage_key, user, rewrite_static_links=True):
    """
    metadata, data, id representation of a leaf module fetcher.
    :param usage_key: A UsageKey
    """
    store = modulestore()
    try:
        module = store.get_item(usage_key)
    except ItemNotFoundError:
        if usage_key.category in CREATE_IF_NOT_FOUND:
            # Create a new one for certain categories only. Used for course info handouts.
            module = store.create_and_save_xmodule(usage_key, user.id)
        else:
            raise

    data = getattr(module, 'data', '')
    if rewrite_static_links:
        data = replace_static_urls(
            data,
            None,
            course_id=module.location.course_key
        )

    # Note that children aren't being returned until we have a use case.
    return {
        'id': unicode(module.location),
        'data': data,
        'metadata': own_metadata(module)
    }
开发者ID:ibrahima,项目名称:edx-platform,代码行数:29,代码来源:item.py

示例13: get_module_info

def get_module_info(store, location, parent_location=None, rewrite_static_links=False):
    try:
        if location.revision is None:
            module = store.get_item(location)
        else:
            module = store.get_item(location)
    except ItemNotFoundError:
        # create a new one
        template_location = Location(
            ['i4x', 'edx', 'templates', location.category, 'Empty'])
        module = store.clone_item(template_location, location)

    data = module.data
    if rewrite_static_links:
        data = replace_static_urls(
            module.data,
            None,
            course_namespace=Location([
                module.location.tag,
                module.location.org,
                module.location.course,
                None,
                None
            ])
        )

    return {
        'id': module.location.url(),
        'data': data,
        # TODO (cpennington): This really shouldn't have to do this much
        # reaching in to get the metadata
        'metadata': module._model_data._kvs._metadata
    }
开发者ID:hughdbrown,项目名称:edx-platform,代码行数:33,代码来源:module_info_model.py

示例14: get_module_info

def get_module_info(store, location, rewrite_static_links=False):
    try:
        module = store.get_item(location)
    except ItemNotFoundError:
        # create a new one
        store.create_and_save_xmodule(location)
        module = store.get_item(location)

    data = module.data
    if rewrite_static_links:
        data = replace_static_urls(
            module.data,
            None,
            course_namespace=Location([
                module.location.tag,
                module.location.org,
                module.location.course,
                None,
                None
            ])
        )

    return {
        'id': module.location.url(),
        'data': data,
        # TODO (cpennington): This really shouldn't have to do this much reaching in to get the metadata
        # what's the intent here? all metadata incl inherited & namespaced?
        'metadata': module.xblock_kvs._metadata
    }
开发者ID:InMooc,项目名称:edx-platform,代码行数:29,代码来源:module_info_model.py

示例15: get_course_syllabus_section

def get_course_syllabus_section(course, section_key):
    """
    This returns the snippet of html to be rendered on the syllabus page,
    given the key for the section.

    Valid keys:
    - syllabus
    - guest_syllabus
    """

    # Many of these are stored as html files instead of some semantic
    # markup. This can change without effecting this interface when we find a
    # good format for defining so many snippets of text/html.

    if section_key in ["syllabus", "guest_syllabus"]:
        try:
            fs = course.system.resources_fs
            # first look for a run-specific version
            dirs = [path("syllabus") / course.url_name, path("syllabus")]
            filepath = find_file(fs, dirs, section_key + ".html")
            with fs.open(filepath) as htmlFile:
                return replace_static_urls(
                    htmlFile.read().decode("utf-8"), getattr(course, "data_dir", None), course_namespace=course.location
                )
        except ResourceNotFoundError:
            log.exception(
                "Missing syllabus section {key} in course {url}".format(key=section_key, url=course.location.url())
            )
            return "! Syllabus missing !"

    raise KeyError("Invalid about key " + str(section_key))
开发者ID:nageshgoyal,项目名称:edx-platform,代码行数:31,代码来源:courses.py


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