diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index fbf8b41c61..e1327df49a 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -358,6 +358,14 @@ class XModuleDescriptor(HTMLSnippet, ResourceTemplates, XBlock): default=None, ) + # VS[compat]. Backwards compatibility code that can go away after + # importing 2012 courses. + # A set of metadata key conversions that we want to make + metadata_translations = { + 'slug': 'url_name', + 'name': 'display_name', + } + # ============================= STRUCTURAL MANIPULATION =================== def __init__(self, system, @@ -493,6 +501,10 @@ class XModuleDescriptor(HTMLSnippet, ResourceTemplates, XBlock): system: A DescriptorSystem for interacting with external resources """ model_data = {} + + for key, value in json_data.get('metadata', {}).items(): + model_data[cls._translate(key)] = value + model_data.update(json_data.get('metadata', {})) definition = json_data.get('definition', {}) @@ -507,6 +519,11 @@ class XModuleDescriptor(HTMLSnippet, ResourceTemplates, XBlock): return cls(system=system, location=json_data['location'], model_data=model_data) + @classmethod + def _translate(cls, key): + 'VS[compat]' + return cls.metadata_translations.get(key, key) + # ================================= XML PARSING ============================ @staticmethod def load_from_xml(xml_data, diff --git a/common/lib/xmodule/xmodule/xml_module.py b/common/lib/xmodule/xmodule/xml_module.py index ae1f7ba27b..e5c1708ac4 100644 --- a/common/lib/xmodule/xmodule/xml_module.py +++ b/common/lib/xmodule/xmodule/xml_module.py @@ -137,18 +137,6 @@ class XmlDescriptor(XModuleDescriptor): 'allow_anonymous_to_peers': bool_map } - # VS[compat]. Backwards compatibility code that can go away after - # importing 2012 courses. - # A set of metadata key conversions that we want to make - metadata_translations = { - 'slug': 'url_name', - 'name': 'display_name', - } - - @classmethod - def _translate(cls, key): - 'VS[compat]' - return cls.metadata_translations.get(key, key) @classmethod def definition_from_xml(cls, xml_object, system):