Add ability to update modulestore metadata for a module separately from data or children

This commit is contained in:
Calen Pennington
2012-06-29 16:04:45 -04:00
parent 51a790173f
commit 7b89b1eb54
4 changed files with 39 additions and 2 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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}}
)

View File

@@ -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")