Merge pull request #1384 from MITx/fix/cdodge/export-static-tabs
adding exporting of tabs and custom_tags. Also added unit tests
This commit is contained in:
@@ -8,6 +8,8 @@ from django.core.urlresolvers import reverse
|
||||
from path import path
|
||||
from tempfile import mkdtemp
|
||||
import json
|
||||
from fs.osfs import OSFS
|
||||
|
||||
|
||||
from student.models import Registration
|
||||
from django.contrib.auth.models import User
|
||||
@@ -457,6 +459,28 @@ class ContentStoreTest(TestCase):
|
||||
# export out to a tempdir
|
||||
export_to_xml(ms, cs, location, root_dir, 'test_export')
|
||||
|
||||
# check for static tabs
|
||||
fs = OSFS(root_dir / 'test_export')
|
||||
self.assertTrue(fs.exists('tabs'))
|
||||
|
||||
static_tabs_query_loc = Location('i4x', location.org, location.course, 'static_tab', None)
|
||||
static_tabs = ms.get_items(static_tabs_query_loc)
|
||||
|
||||
for static_tab in static_tabs:
|
||||
fs = OSFS(root_dir / 'test_export/tabs')
|
||||
self.assertTrue(fs.exists(static_tab.location.name + '.html'))
|
||||
|
||||
# check for custom_tags
|
||||
fs = OSFS(root_dir / 'test_export')
|
||||
self.assertTrue(fs.exists('custom_tags'))
|
||||
|
||||
custom_tags_query_loc = Location('i4x', location.org, location.course, 'custom_tag_template', None)
|
||||
custom_tags = ms.get_items(custom_tags_query_loc)
|
||||
|
||||
for custom_tag in custom_tags:
|
||||
fs = OSFS(root_dir / 'test_export/custom_tags')
|
||||
self.assertTrue(fs.exists(custom_tag.location.name))
|
||||
|
||||
# remove old course
|
||||
delete_course(ms, cs, location)
|
||||
|
||||
|
||||
@@ -17,4 +17,23 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d
|
||||
# export the static assets
|
||||
contentstore.export_all_for_course(course_location, root_dir + '/' + course_dir + '/static/')
|
||||
|
||||
# export the static tabs
|
||||
export_extra_content(export_fs, modulestore, course_location, 'static_tab', 'tabs', '.html')
|
||||
|
||||
# export the custom tags
|
||||
export_extra_content(export_fs, modulestore, course_location, 'custom_tag_template', 'custom_tags')
|
||||
|
||||
|
||||
def export_extra_content(export_fs, modulestore, course_location, category_type, dirname, file_suffix = ''):
|
||||
query_loc = Location('i4x', course_location.org, course_location.course, category_type, None)
|
||||
items = modulestore.get_items(query_loc)
|
||||
|
||||
if len(items) > 0:
|
||||
item_dir = export_fs.makeopendir(dirname)
|
||||
for item in items:
|
||||
with item_dir.open(item.location.name + file_suffix, 'w') as item_file:
|
||||
item_file.write(item.definition['data'].encode('utf8'))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user