diff --git a/cms/djangoapps/contentstore/management/commands/import.py b/cms/djangoapps/contentstore/management/commands/import.py index 12806debb7668cac95cbd6f0a4dfbb8edc77f5ca..bb9697d6a16c5357da2d15422c7b3ae6924aff77 100644 --- a/cms/djangoapps/contentstore/management/commands/import.py +++ b/cms/djangoapps/contentstore/management/commands/import.py @@ -26,3 +26,4 @@ class Command(BaseCommand): keystore().update_item(module.location, module.definition['data']) if 'children' in module.definition: keystore().update_children(module.location, module.definition['children']) + keystore().update_metadata(module.url, module.metadata) diff --git a/common/lib/keystore/__init__.py b/common/lib/keystore/__init__.py index 0671e7e568603d876558e38c384e8380956fab7c..43ffa464ffaea6b21d7bc8f04001f39bc74fdf01 100644 --- a/common/lib/keystore/__init__.py +++ b/common/lib/keystore/__init__.py @@ -171,9 +171,19 @@ class ModuleStore(object): def update_children(self, location, children): """ Set the children for the item specified by the location to - data + children location: Something that can be passed to Location children: A list of child item identifiers """ raise NotImplementedError + + def update_metadata(self, location, metadata): + """ + Set the metadata for the item specified by the location to + metadata + + location: Something that can be passed to Location + metadata: A nested dictionary of module metadata + """ + raise NotImplementedError diff --git a/common/lib/keystore/mongo.py b/common/lib/keystore/mongo.py index 4c50b634eaec2057ed5cf939605674e8a72ab2b0..d92782600c04bf36a0ad690b5d19ad78fd313348 100644 --- a/common/lib/keystore/mongo.py +++ b/common/lib/keystore/mongo.py @@ -85,7 +85,7 @@ class MongoModuleStore(ModuleStore): def update_children(self, location, children): """ Set the children for the item specified by the location to - data + children location: Something that can be passed to Location children: A list of child item identifiers @@ -97,3 +97,19 @@ class MongoModuleStore(ModuleStore): {'location': Location(location).dict()}, {'$set': {'definition.children': children}} ) + + def update_metadata(self, location, metadata): + """ + Set the children for the item specified by the location to + metadata + + location: Something that can be passed to Location + metadata: A nested dictionary of module metadata + """ + + # See http://www.mongodb.org/display/DOCS/Updating for + # atomic update syntax + self.collection.update( + {'location': Location(location).dict()}, + {'$set': {'metadata': metadata}} + ) diff --git a/common/lib/keystore/xml.py b/common/lib/keystore/xml.py index e7adb56ad6e98a69639c26810dfd1fb6a566930b..d475077733ccaf071e700ea23b2da8f7fec9e5a3 100644 --- a/common/lib/keystore/xml.py +++ b/common/lib/keystore/xml.py @@ -94,3 +94,13 @@ class XMLModuleStore(ModuleStore): children: A list of child item identifiers """ raise NotImplementedError("XMLModuleStores are read-only") + + def update_metadata(self, location, metadata): + """ + Set the metadata for the item specified by the location to + metadata + + location: Something that can be passed to Location + metadata: A nested dictionary of module metadata + """ + raise NotImplementedError("XMLModuleStores are read-only")