From 069f997595171a94457ada259ff5567617cd9efa Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 8 Apr 2013 14:33:46 -0400 Subject: [PATCH 1/4] import was putting the xml data into definition.data.data rather than definition.data --- .../lib/xmodule/xmodule/modulestore/xml_importer.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index 53eaebf850..2047f016ae 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -284,7 +284,7 @@ def import_from_xml(store, data_dir, course_dirs=None, except KeyError: # Ignore any missing keys in _model_data pass - + if 'data' in content: module_data = content['data'] @@ -301,16 +301,17 @@ def import_from_xml(store, data_dir, course_dirs=None, # Note the dropped element closing tag. This causes the LMS to fail when rendering modules - that's # no good, so we have to do this kludge if isinstance(module_data, str) or isinstance(module_data, unicode): # some module 'data' fields are non strings which blows up the link traversal code - lxml_rewrite_links(module_data, lambda link: verify_content_links(module, course_data_path, - static_content_store, link, remap_dict)) + lxml_rewrite_links(module_data, lambda link: + verify_content_links(module, course_data_path, + static_content_store, link, remap_dict)) for key in remap_dict.keys(): module_data = module_data.replace(key, remap_dict[key]) - except Exception, e: + except Exception: logging.exception("failed to rewrite links on {0}. Continuing...".format(module.location)) - store.update_item(module.location, content) + store.update_item(module.location, module_data) if hasattr(module, 'children') and module.children != []: store.update_children(module.location, module.children) From 0b26cc263520752b8b1782fb495be0095dffeb87 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 8 Apr 2013 14:48:16 -0400 Subject: [PATCH 2/4] fix line breaks per Cale --- common/lib/xmodule/xmodule/modulestore/xml_importer.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index 2047f016ae..1a48bc647c 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -301,9 +301,8 @@ def import_from_xml(store, data_dir, course_dirs=None, # Note the dropped element closing tag. This causes the LMS to fail when rendering modules - that's # no good, so we have to do this kludge if isinstance(module_data, str) or isinstance(module_data, unicode): # some module 'data' fields are non strings which blows up the link traversal code - lxml_rewrite_links(module_data, lambda link: - verify_content_links(module, course_data_path, - static_content_store, link, remap_dict)) + lxml_rewrite_links(module_data, + lambda link: verify_content_links(module, course_data_path, static_content_store, link, remap_dict)) for key in remap_dict.keys(): module_data = module_data.replace(key, remap_dict[key]) From a0f5a51135274241f2f469078b8f75222f973249 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 8 Apr 2013 15:34:12 -0400 Subject: [PATCH 3/4] wip to fix broken test --- common/lib/xmodule/xmodule/modulestore/xml_importer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index 1a48bc647c..97b3396baa 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -309,6 +309,8 @@ def import_from_xml(store, data_dir, course_dirs=None, except Exception: logging.exception("failed to rewrite links on {0}. Continuing...".format(module.location)) + else: + module_data = content store.update_item(module.location, module_data) From 54afc5eb6331c700936a7cca6e9b15e60abbf4ca Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 8 Apr 2013 16:09:41 -0400 Subject: [PATCH 4/4] seems like we need to purge 'filename' from both _model_data as well as xml_attributes --- common/lib/xmodule/xmodule/tests/test_export.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/lib/xmodule/xmodule/tests/test_export.py b/common/lib/xmodule/xmodule/tests/test_export.py index 443014f9ef..170a89d783 100644 --- a/common/lib/xmodule/xmodule/tests/test_export.py +++ b/common/lib/xmodule/xmodule/tests/test_export.py @@ -24,6 +24,11 @@ def strip_filenames(descriptor): """ print "strip filename from {desc}".format(desc=descriptor.location.url()) descriptor._model_data.pop('filename', None) + + if hasattr(descriptor, 'xml_attributes'): + if 'filename' in descriptor.xml_attributes: + del descriptor.xml_attributes['filename'] + for d in descriptor.get_children(): strip_filenames(d)