示例#1
0
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)
def replace_course_urls(course_id, block, view, frag, context):  # pylint: disable=unused-argument
    """
    Updates the supplied module with a new get_html function that wraps
    the old get_html function and substitutes urls of the form /course/...
    with urls that are /courses/<course_id>/...
    """
    return wrap_fragment(frag, static_replace.replace_course_urls(frag.content, course_id))
示例#3
0
    def replace_urls(self, text, static_replace_only=False):
        """
        Replaces all static/course/jump-to-id URLs in provided text/html.

        Args:
            text: String containing the URL to be replaced
            static_replace_only: If True, only static urls will be replaced
        """
        if self.lookup_asset_url:
            text = replace_static_urls(text,
                                       xblock=self.xblock(),
                                       lookup_asset_url=self.lookup_asset_url)
        else:
            text = replace_static_urls(
                text,
                data_directory=self.data_directory,
                course_id=self.course_id,
                static_asset_path=self.static_asset_path,
                static_paths_out=self.static_paths_out)
            if not static_replace_only:
                text = replace_course_urls(text, self.course_id)
                if self.jump_to_id_base_url:
                    text = replace_jump_to_id_urls(text, self.course_id,
                                                   self.jump_to_id_base_url)

        return text