From 55bfe46e79c944e8a25c8e9c2c33b7173513ae55 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 7 Aug 2013 12:13:27 -0400 Subject: [PATCH] need to filter out non-own metadata. Also we need to clone draft content --- .../xmodule/modulestore/store_utilities.py | 69 ++++++++++--------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/store_utilities.py b/common/lib/xmodule/xmodule/modulestore/store_utilities.py index 3c29627d84..e941cf5224 100644 --- a/common/lib/xmodule/xmodule/modulestore/store_utilities.py +++ b/common/lib/xmodule/xmodule/modulestore/store_utilities.py @@ -1,10 +1,45 @@ from xmodule.contentstore.content import StaticContent from xmodule.modulestore import Location from xmodule.modulestore.mongo import MongoModuleStore +from xmodule.modulestore.inheritance import own_metadata import logging +def _clone_modules(modulestore, modules, dest_location): + for module in modules: + original_loc = Location(module.location) + + if original_loc.category != 'course': + module.location = module.location._replace(tag=dest_location.tag, org=dest_location.org, + course=dest_location.course) + else: + # on the course module we also have to update the module name + module.location = module.location._replace(tag=dest_location.tag, org=dest_location.org, + course=dest_location.course, name=dest_location.name) + + print "Cloning module {0} to {1}....".format(original_loc, module.location) + + modulestore.update_item(module.location, module._model_data._kvs._data) + + # repoint children + if module.has_children: + new_children = [] + for child_loc_url in module.children: + child_loc = Location(child_loc_url) + child_loc = child_loc._replace( + tag=dest_location.tag, + org=dest_location.org, + course=dest_location.course + ) + new_children.append(child_loc.url()) + + modulestore.update_children(module.location, new_children) + + # save metadata + modulestore.update_metadata(module.location, own_metadata(module)) + + def clone_course(modulestore, contentstore, source_location, dest_location, delete_original=False): # first check to see if the modulestore is Mongo backed if not isinstance(modulestore, MongoModuleStore): @@ -37,38 +72,10 @@ def clone_course(modulestore, contentstore, source_location, dest_location, dele # Get all modules under this namespace which is (tag, org, course) tuple modules = modulestore.get_items([source_location.tag, source_location.org, source_location.course, None, None, None]) + _clone_modules(modulestore, modules, dest_location) - for module in modules: - original_loc = Location(module.location) - - if original_loc.category != 'course': - module.location = module.location._replace(tag=dest_location.tag, org=dest_location.org, - course=dest_location.course) - else: - # on the course module we also have to update the module name - module.location = module.location._replace(tag=dest_location.tag, org=dest_location.org, - course=dest_location.course, name=dest_location.name) - - print "Cloning module {0} to {1}....".format(original_loc, module.location) - - modulestore.update_item(module.location, module._model_data._kvs._data) - - # repoint children - if module.has_children: - new_children = [] - for child_loc_url in module.children: - child_loc = Location(child_loc_url) - child_loc = child_loc._replace( - tag=dest_location.tag, - org=dest_location.org, - course=dest_location.course - ) - new_children.append(child_loc.url()) - - modulestore.update_children(module.location, new_children) - - # save metadata - modulestore.update_metadata(module.location, module._model_data._kvs._metadata) + modules = modulestore.get_items([source_location.tag, source_location.org, source_location.course, None, None, 'draft']) + _clone_modules(modulestore, modules, dest_location) # now iterate through all of the assets and clone them # first the thumbnails