From 958597ac71c2f509573073cb7fbd5c4128795cfd Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 14 Aug 2013 23:09:06 -0400 Subject: [PATCH 01/11] was getting unicode errors when exporting CB22x --- cms/djangoapps/contentstore/views/assets.py | 3 +++ common/lib/xmodule/xmodule/video_module.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/views/assets.py b/cms/djangoapps/contentstore/views/assets.py index 94bfa55b58..b35f00f0e2 100644 --- a/cms/djangoapps/contentstore/views/assets.py +++ b/cms/djangoapps/contentstore/views/assets.py @@ -348,6 +348,8 @@ def generate_export_course(request, org, course, name): try: export_to_xml(modulestore('direct'), contentstore(), loc, root_dir, name, modulestore()) except SerializationError, e: + logging.exception('There was an error exporting course {0}. {1}'.format(course_module.location, unicode(e))) + unit = None failed_item = None parent = None @@ -380,6 +382,7 @@ def generate_export_course(request, org, course, name): }) }) except Exception, e: + logging.exception('There was an error exporting course {0}. {1}'.format(course_module.location, unicode(e))) return render_to_response('export.html', { 'context_course': course_module, 'successful_import_redirect_url': '', diff --git a/common/lib/xmodule/xmodule/video_module.py b/common/lib/xmodule/xmodule/video_module.py index 407547d9bf..afa811b718 100644 --- a/common/lib/xmodule/xmodule/video_module.py +++ b/common/lib/xmodule/xmodule/video_module.py @@ -266,7 +266,7 @@ class VideoDescriptor(VideoFields, TabsEditingDescriptor, EmptyDataRawDescriptor if key in fields and fields[key].default == getattr(self, key): continue if value: - xml.set(key, str(value)) + xml.set(key, unicode(value)) for source in self.html5_sources: ele = etree.Element('source') From 26651a1dd7e4d9267764586cba620282eae08c3d Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 14 Aug 2013 23:35:40 -0400 Subject: [PATCH 02/11] export_to_xml() really should be definition_to_xml() since we'll rely on the base method that is in xml_module.py to preserve the correct export filesystem hierarchy. --- common/lib/xmodule/xmodule/video_module.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/video_module.py b/common/lib/xmodule/xmodule/video_module.py index afa811b718..c8c0bf4225 100644 --- a/common/lib/xmodule/xmodule/video_module.py +++ b/common/lib/xmodule/xmodule/video_module.py @@ -240,7 +240,7 @@ class VideoDescriptor(VideoFields, TabsEditingDescriptor, EmptyDataRawDescriptor video = cls(system, model_data) return video - def export_to_xml(self, resource_fs): + def definition_to_xml(self, resource_fs): """ Returns an xml string representing this module. """ @@ -277,7 +277,8 @@ class VideoDescriptor(VideoFields, TabsEditingDescriptor, EmptyDataRawDescriptor ele = etree.Element('track') ele.set('src', self.track) xml.append(ele) - return etree.tostring(xml, pretty_print=True) + return xml + #return etree.tostring(xml, pretty_print=True) @staticmethod def _parse_youtube(data): From 43f2c6a8e4c20bce937307de2a629534f9478de8 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Thu, 15 Aug 2013 00:28:16 -0400 Subject: [PATCH 03/11] remove commented out line --- common/lib/xmodule/xmodule/video_module.py | 1 - 1 file changed, 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/video_module.py b/common/lib/xmodule/xmodule/video_module.py index c8c0bf4225..8f5b4b4d09 100644 --- a/common/lib/xmodule/xmodule/video_module.py +++ b/common/lib/xmodule/xmodule/video_module.py @@ -278,7 +278,6 @@ class VideoDescriptor(VideoFields, TabsEditingDescriptor, EmptyDataRawDescriptor ele.set('src', self.track) xml.append(ele) return xml - #return etree.tostring(xml, pretty_print=True) @staticmethod def _parse_youtube(data): From f27ed07305994a9cd5e0c591de77e22fbf2ac547 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Thu, 15 Aug 2013 01:04:55 -0400 Subject: [PATCH 04/11] update tests to call definition_to_xml rather than export_to_xml, which presumes writing to a filesystem, plus it adds a url_name to the attribute set. Also, on __init__ reset the 'category' attribute, on some code paths this can get lost. Not sure why, but this gets all the tests to pass. --- common/lib/xmodule/xmodule/tests/test_video.py | 9 +++++---- common/lib/xmodule/xmodule/video_module.py | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/tests/test_video.py b/common/lib/xmodule/xmodule/tests/test_video.py index 4a13d565cc..ac1ab1d247 100644 --- a/common/lib/xmodule/xmodule/tests/test_video.py +++ b/common/lib/xmodule/xmodule/tests/test_video.py @@ -15,6 +15,7 @@ the course, section, subsection, unit, etc. import unittest from . import LogicTest +from lxml import etree from .import get_test_system from xmodule.modulestore import Location from xmodule.video_module import VideoDescriptor, _create_youtube_string @@ -344,7 +345,7 @@ class VideoExportTestCase(unittest.TestCase): desc.track = 'http://www.example.com/track' desc.html5_sources = ['http://www.example.com/source.mp4', 'http://www.example.com/source.ogg'] - xml = desc.export_to_xml(None) # We don't use the `resource_fs` parameter + xml = desc.definition_to_xml(None) # We don't use the `resource_fs` parameter expected = dedent('''\ ''') - self.assertEquals(expected, xml) + self.assertEquals(expected, etree.tostring(xml, pretty_print=True)) def test_export_to_xml_empty_parameters(self): """Test XML export with defaults.""" @@ -361,7 +362,7 @@ class VideoExportTestCase(unittest.TestCase): location = Location(["i4x", "edX", "video", "default", "SampleProblem1"]) desc = VideoDescriptor(module_system, {'location': location}) - xml = desc.export_to_xml(None) + xml = desc.definition_to_xml(None) expected = '