Commit d354571e by Calen Pennington

Use field scopes to compute which metadata to strip from the definition during…

Use field scopes to compute which metadata to strip from the definition during XML import of XMLModule subclasses
parent 9a4e1f5c
...@@ -125,11 +125,6 @@ class CapaDescriptor(CapaFields, RawDescriptor): ...@@ -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 # The capa format specifies that what we call max_attempts in the code
# is the attribute `attempts`. This will do that conversion # is the attribute `attempts`. This will do that conversion
metadata_translations = dict(RawDescriptor.metadata_translations) metadata_translations = dict(RawDescriptor.metadata_translations)
......
...@@ -497,8 +497,6 @@ class CombinedOpenEndedDescriptor(CombinedOpenEndedFields, RawDescriptor): ...@@ -497,8 +497,6 @@ class CombinedOpenEndedDescriptor(CombinedOpenEndedFields, RawDescriptor):
#Specify whether or not to pass in open ended interface #Specify whether or not to pass in open ended interface
needs_open_ended_interface = True needs_open_ended_interface = True
metadata_attributes = RawDescriptor.metadata_attributes
js = {'coffee': [resource_string(__name__, 'js/src/combinedopenended/edit.coffee')]} js = {'coffee': [resource_string(__name__, 'js/src/combinedopenended/edit.coffee')]}
js_module_name = "OpenEndedMarkdownEditingDescriptor" js_module_name = "OpenEndedMarkdownEditingDescriptor"
css = {'scss': [resource_string(__name__, 'css/editor/edit.scss'), resource_string(__name__, 'css/combinedopenended/edit.scss')]} css = {'scss': [resource_string(__name__, 'css/editor/edit.scss'), resource_string(__name__, 'css/combinedopenended/edit.scss')]}
......
...@@ -123,17 +123,6 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -123,17 +123,6 @@ class XmlDescriptor(XModuleDescriptor):
# Note -- url_name isn't in this list because it's handled specially on # Note -- url_name isn't in this list because it's handled specially on
# import and export. # 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', metadata_to_strip = ('data_dir',
'tabs', 'grading_policy', 'published_by', 'published_date', 'tabs', 'grading_policy', 'published_by', 'published_date',
'discussion_blackouts', 'discussion_blackouts',
...@@ -157,12 +146,12 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -157,12 +146,12 @@ class XmlDescriptor(XModuleDescriptor):
@classmethod @classmethod
def clean_metadata_from_xml(cls, xml_object): 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 xml_object
""" """
for attr in cls.metadata_attributes: for field_name, field in cls.fields.items():
if xml_object.get(attr) is not None: if field.scope == Scope.settings and xml_object.get(field_name) is not None:
del xml_object.attrib[attr] del xml_object.attrib[field_name]
@classmethod @classmethod
def file_to_xml(cls, file_object): def file_to_xml(cls, file_object):
...@@ -220,6 +209,9 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -220,6 +209,9 @@ class XmlDescriptor(XModuleDescriptor):
definition_xml = cls.load_file(filepath, system.resources_fs, def_id) 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) definition_metadata = get_metadata_from_xml(definition_xml)
cls.clean_metadata_from_xml(definition_xml) cls.clean_metadata_from_xml(definition_xml)
definition, children = cls.definition_from_xml(definition_xml, system) definition, children = cls.definition_from_xml(definition_xml, system)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment