fix for inheriting metadata bug

* problem was on import to json--got all the metadata,
  but didn't preserve the _inherited_metadata
* added own_metadata property, use it instead
This commit is contained in:
Victor Shnayder
2012-08-01 19:22:14 -04:00
parent b63f05b651
commit 652e2aa24c
3 changed files with 14 additions and 1 deletions

View File

@@ -41,6 +41,9 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem):
self.used_slugs = set()
def process_xml(xml):
"""Takes an xml string, and returns a XModuleDescriptor created from
that xml.
"""
try:
# VS[compat]
# TODO (cpennington): Remove this once all fall 2012 courses

View File

@@ -35,6 +35,8 @@ def import_from_xml(store, data_dir, course_dirs=None, eager=True,
store.update_item(module.location, module.definition['data'])
if 'children' in module.definition:
store.update_children(module.location, module.definition['children'])
store.update_metadata(module.location, dict(module.metadata))
# NOTE: It's important to use own_metadata here to avoid writing
# inherited metadata everywhere.
store.update_metadata(module.location, dict(module.own_metadata))
return module_store

View File

@@ -358,6 +358,14 @@ class XModuleDescriptor(Plugin, HTMLSnippet):
self._child_instances = None
self._inherited_metadata = set()
@property
def own_metadata(self):
"""
Return the metadata that is not inherited, but was defined on this module.
"""
return dict((k,v) for k,v in self.metadata.items()
if k not in self._inherited_metadata)
def inherit_metadata(self, metadata):
"""
Updates this module with metadata inherited from a containing module.