From d354571e956f411aca8465fec6d30af4846e1dbd Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 16 Jul 2014 10:52:04 -0400 Subject: [PATCH] Use field scopes to compute which metadata to strip from the definition during XML import of XMLModule subclasses --- common/lib/xmodule/xmodule/capa_module.py | 5 ----- .../xmodule/combined_open_ended_module.py | 2 -- common/lib/xmodule/xmodule/xml_module.py | 22 ++++++------------- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index 84bc8b768f..b8dc24cf68 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -125,11 +125,6 @@ class CapaDescriptor(CapaFields, RawDescriptor): ] } - # Capa modules have some additional metadata: - # TODO (vshnayder): do problems have any other metadata? Do they - # actually use type and points? - metadata_attributes = RawDescriptor.metadata_attributes + ('type', 'points') - # The capa format specifies that what we call max_attempts in the code # is the attribute `attempts`. This will do that conversion metadata_translations = dict(RawDescriptor.metadata_translations) diff --git a/common/lib/xmodule/xmodule/combined_open_ended_module.py b/common/lib/xmodule/xmodule/combined_open_ended_module.py index ee48c8cbe7..11eece3e1d 100644 --- a/common/lib/xmodule/xmodule/combined_open_ended_module.py +++ b/common/lib/xmodule/xmodule/combined_open_ended_module.py @@ -497,8 +497,6 @@ class CombinedOpenEndedDescriptor(CombinedOpenEndedFields, RawDescriptor): #Specify whether or not to pass in open ended interface needs_open_ended_interface = True - metadata_attributes = RawDescriptor.metadata_attributes - js = {'coffee': [resource_string(__name__, 'js/src/combinedopenended/edit.coffee')]} js_module_name = "OpenEndedMarkdownEditingDescriptor" css = {'scss': [resource_string(__name__, 'css/editor/edit.scss'), resource_string(__name__, 'css/combinedopenended/edit.scss')]} diff --git a/common/lib/xmodule/xmodule/xml_module.py b/common/lib/xmodule/xmodule/xml_module.py index 1092765821..4676b14159 100644 --- a/common/lib/xmodule/xmodule/xml_module.py +++ b/common/lib/xmodule/xmodule/xml_module.py @@ -123,17 +123,6 @@ class XmlDescriptor(XModuleDescriptor): # Note -- url_name isn't in this list because it's handled specially on # import and export. - # TODO (vshnayder): Do we need a list of metadata we actually - # understand? And if we do, is this the place? - # Related: What's the right behavior for clean_metadata? - metadata_attributes = ('format', 'graceperiod', 'showanswer', 'rerandomize', - 'start', 'due', 'graded', 'display_name', 'url_name', 'hide_from_toc', - 'ispublic', # if True, then course is listed for all users; see - 'xqa_key', # for xqaa server access - 'giturl', # url of git server for origin of file - # VS[compat] Remove once unused. - 'name', 'slug') - metadata_to_strip = ('data_dir', 'tabs', 'grading_policy', 'published_by', 'published_date', 'discussion_blackouts', @@ -157,12 +146,12 @@ class XmlDescriptor(XModuleDescriptor): @classmethod def clean_metadata_from_xml(cls, xml_object): """ - Remove any attribute named in cls.metadata_attributes from the supplied + Remove any attribute named for a field with scope Scope.settings from the supplied xml_object """ - for attr in cls.metadata_attributes: - if xml_object.get(attr) is not None: - del xml_object.attrib[attr] + for field_name, field in cls.fields.items(): + if field.scope == Scope.settings and xml_object.get(field_name) is not None: + del xml_object.attrib[field_name] @classmethod def file_to_xml(cls, file_object): @@ -220,6 +209,9 @@ class XmlDescriptor(XModuleDescriptor): definition_xml = cls.load_file(filepath, system.resources_fs, def_id) + # Add the attributes from the pointer node + definition_xml.attrib.update(xml_object.attrib) + definition_metadata = get_metadata_from_xml(definition_xml) cls.clean_metadata_from_xml(definition_xml) definition, children = cls.definition_from_xml(definition_xml, system)