add ability to rewrite links on the old /courses/<org>/<course>/<run>/jump_to/i4x://<org>/<course> .. intracourseware linking to the new portable /jump_to_id/<id> format
This commit is contained in:
@@ -777,11 +777,16 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
|
||||
|
||||
import_from_xml(module_store, 'common/test/data/', ['toy'], static_content_store=content_store)
|
||||
|
||||
# first check a static asset link
|
||||
html_module_location = Location(['i4x', 'edX', 'toy', 'html', 'nonportable'])
|
||||
html_module = module_store.get_instance('edX/toy/2012_Fall', html_module_location)
|
||||
|
||||
self.assertIn('/static/foo.jpg', html_module.data)
|
||||
|
||||
# then check a intra courseware link
|
||||
html_module_location = Location(['i4x', 'edX', 'toy', 'html', 'nonportable_link'])
|
||||
html_module = module_store.get_instance('edX/toy/2012_Fall', html_module_location)
|
||||
self.assertIn('/jump_to_id/nonportable_link', html_module.data)
|
||||
|
||||
def test_delete_course(self):
|
||||
"""
|
||||
This test will import a course, make a draft item, and delete it. This will also assert that the
|
||||
|
||||
@@ -3,11 +3,43 @@ from xmodule.contentstore.content import StaticContent
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.modulestore.mongo import MongoModuleStore
|
||||
from xmodule.modulestore.inheritance import own_metadata
|
||||
from static_replace import _url_replace_regex
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
def _asset_url_replace_regex(prefix):
|
||||
"""
|
||||
Match static urls in quotes that don't end in '?raw'.
|
||||
|
||||
To anyone contemplating making this more complicated:
|
||||
http://xkcd.com/1171/
|
||||
"""
|
||||
return r"""
|
||||
(?x) # flags=re.VERBOSE
|
||||
(?P<quote>\\?['"]) # the opening quotes
|
||||
(?P<prefix>{prefix}) # the prefix
|
||||
(?P<rest>.*?) # everything else in the url
|
||||
(?P=quote) # the first matching closing quote
|
||||
""".format(prefix=prefix)
|
||||
|
||||
|
||||
def _jump_to_url_replace_regex(prefix):
|
||||
"""
|
||||
Match static urls in quotes that don't end in '?raw'.
|
||||
|
||||
To anyone contemplating making this more complicated:
|
||||
http://xkcd.com/1171/
|
||||
"""
|
||||
return r"""
|
||||
(?x) # flags=re.VERBOSE
|
||||
(?P<quote>\\?['"]) # the opening quotes
|
||||
(?P<prefix>{prefix}) # the prefix
|
||||
(?P<category>[^/]+)/
|
||||
(?P<rest>.*?) # everything else in the url
|
||||
(?P=quote) # the first matching closing quote
|
||||
""".format(prefix=prefix)
|
||||
|
||||
|
||||
def convert_to_portable_links(source_course_id, text):
|
||||
"""
|
||||
Does a regex replace on non-portable links:
|
||||
@@ -20,11 +52,20 @@ def convert_to_portable_links(source_course_id, text):
|
||||
rest = match.group('rest')
|
||||
return "".join([quote, '/static/'+rest, quote])
|
||||
|
||||
def portable_jump_to_link_substitution(match):
|
||||
quote = match.group('quote')
|
||||
rest = match.group('rest')
|
||||
return "".join([quote, '/jump_to_id/'+rest, quote])
|
||||
|
||||
org, course, run = source_course_id.split("/")
|
||||
course_location = Location(['i4x', org, course, 'course', run])
|
||||
|
||||
c4x_link_base = '{0}/'.format(StaticContent.get_base_url_path_for_course_assets(course_location))
|
||||
text = re.sub(_url_replace_regex(c4x_link_base), portable_asset_link_subtitution, text)
|
||||
text = re.sub(_asset_url_replace_regex(c4x_link_base), portable_asset_link_subtitution, text)
|
||||
|
||||
jump_to_link_base = '/courses/{org}/{course}/{run}/jump_to/i4x://{org}/{course}/'.format(
|
||||
org=org, course=course, run=run)
|
||||
text = re.sub(_jump_to_url_replace_regex(jump_to_link_base), portable_jump_to_link_substitution, text)
|
||||
|
||||
return text
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<html url_name="toyjumpto"/>
|
||||
<html url_name="toyhtml"/>
|
||||
<html url_name="nonportable"/>
|
||||
<html url_name="nonportable_link"/>
|
||||
<video url_name="Video_Resources" youtube_id_1_0="1bK-WdDi6Qw" display_name="Video Resources"/>
|
||||
</videosequence>
|
||||
<video url_name="Welcome" youtube_id_1_0="p2Q6BrNhdh8" display_name="Welcome"/>
|
||||
|
||||
Reference in New Issue
Block a user