Commit 9cd38d11 by Chris Dodge

import needs to enumerate through the fields for all content scopes. Also add unit test

parent 93eebdcd
...@@ -101,6 +101,20 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -101,6 +101,20 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertEqual(reverse_tabs, course_tabs) self.assertEqual(reverse_tabs, course_tabs)
def test_import_polls(self):
import_from_xml(modulestore(), 'common/test/data/', ['full'])
module_store = modulestore('direct')
found = False
item = None
items = module_store.get_items(['i4x', 'edX', 'full', 'poll_question', None, None])
found = len(items) > 0
self.assertTrue(found)
# check that there's actually content in the 'question' field
self.assertGreater(len(items[0].question),0)
def test_delete(self): def test_delete(self):
import_from_xml(modulestore(), 'common/test/data/', ['full']) import_from_xml(modulestore(), 'common/test/data/', ['full'])
......
...@@ -4,6 +4,8 @@ import mimetypes ...@@ -4,6 +4,8 @@ import mimetypes
from lxml.html import rewrite_links as lxml_rewrite_links from lxml.html import rewrite_links as lxml_rewrite_links
from path import path from path import path
from xblock.core import Scope
from .xml import XMLModuleStore from .xml import XMLModuleStore
from .exceptions import DuplicateItemError from .exceptions import DuplicateItemError
from xmodule.modulestore import Location from xmodule.modulestore import Location
...@@ -273,8 +275,18 @@ def import_from_xml(store, data_dir, course_dirs=None, ...@@ -273,8 +275,18 @@ def import_from_xml(store, data_dir, course_dirs=None,
if verbose: if verbose:
log.debug('importing module location {0}'.format(module.location)) log.debug('importing module location {0}'.format(module.location))
if hasattr(module, 'data'): content = {}
module_data = module.data for field in module.fields:
if field.scope != Scope.content:
continue
try:
content[field.name] = module._model_data[field.name]
except KeyError:
# Ignore any missing keys in _model_data
pass
if 'data' in content:
module_data = content['data']
# cdodge: now go through any link references to '/static/' and make sure we've imported # cdodge: now go through any link references to '/static/' and make sure we've imported
# it as a StaticContent asset # it as a StaticContent asset
...@@ -298,7 +310,7 @@ def import_from_xml(store, data_dir, course_dirs=None, ...@@ -298,7 +310,7 @@ def import_from_xml(store, data_dir, course_dirs=None,
except Exception, e: except Exception, e:
logging.exception("failed to rewrite links on {0}. Continuing...".format(module.location)) logging.exception("failed to rewrite links on {0}. Continuing...".format(module.location))
store.update_item(module.location, module_data) store.update_item(module.location, content)
if hasattr(module, 'children') and module.children != []: if hasattr(module, 'children') and module.children != []:
store.update_children(module.location, module.children) store.update_children(module.location, module.children)
......
...@@ -7,4 +7,9 @@ ...@@ -7,4 +7,9 @@
<customtag tag="S1" slug="discuss_91" impl="discuss"/> <customtag tag="S1" slug="discuss_91" impl="discuss"/>
<customtag page="70" slug="book_92" impl="book"/> <customtag page="70" slug="book_92" impl="book"/>
<customtag lecnum="1" slug="slides_93" impl="slides"/> <customtag lecnum="1" slug="slides_93" impl="slides"/>
<poll_question name="T1_changemind_poll_foo" display_name="Change your answer" reset="false">
<p>Have you changed your mind?</p>
<answer id="yes">Yes</answer>
<answer id="no">No</answer>
</poll_question>
</sequential> </sequential>
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