update the PDF textbook url paths as well as update wiki_slug when importing

This commit is contained in:
Chris Dodge
2013-08-20 21:50:28 -04:00
parent e79f8c437a
commit 5989bf6bdc
4 changed files with 58 additions and 2 deletions

View File

@@ -58,6 +58,16 @@ class StaticContent(object):
else:
return None
@staticmethod
def is_c4x_path(path_string):
return path_string.startswith('/{0}/'.format(XASSET_LOCATION_TAG))
@staticmethod
def renamespace_c4x_path(path_string, target_location):
location = StaticContent.get_location_from_path(path_string)
location = location.replace(org=target_location.org, course=target_location.course)
return StaticContent.get_url_path_from_location(location)
@staticmethod
def get_static_path_from_location(location):
"""

View File

@@ -329,8 +329,28 @@ def remap_namespace(module, target_location_namespace):
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'):

View File

@@ -12,7 +12,16 @@
{"type": "discussion", "name": "Discussion"},
{"type": "wiki", "name": "Wiki"},
{"type": "progress", "name": "Progress"}
]
],
"pdf_textbooks": [
{
"tab_title": "Sample Multi Chapter Textbook",
"id": "MyTextbook",
"chapters": [
{ "url": "/c4x/edX/toy/asset/Chapter1.pdf", "title": "Chapter 1"},
{ "url": "/c4x/edX/toy/asset/Chapter2.pdf", "title": "Chapter 2"}
]
}]
},
"chapter/Overview": {
"display_name": "Overview"