From 7b89b1eb54ae66cbdb97254db364832a43ceafa0 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 29 Jun 2012 16:04:45 -0400 Subject: [PATCH] Add ability to update modulestore metadata for a module separately from data or children --- .../contentstore/management/commands/import.py | 1 + common/lib/keystore/__init__.py | 12 +++++++++++- common/lib/keystore/mongo.py | 18 +++++++++++++++++- common/lib/keystore/xml.py | 10 ++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/import.py b/cms/djangoapps/contentstore/management/commands/import.py index 12806debb7..bb9697d6a1 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 0671e7e568..43ffa464ff 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 4c50b634ea..d92782600c 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 e7adb56ad6..d475077733 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")