From 66c91b704a2a50ff7c4ae581de2b451f3b809451 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Fri, 15 Feb 2013 17:16:05 -0500 Subject: [PATCH] init work. Export the 'draft' store under a distinct folder in the export. TBD: do the import from that directory as well. --- cms/djangoapps/contentstore/views.py | 2 +- .../lib/xmodule/xmodule/modulestore/draft.py | 4 ++++ .../xmodule/modulestore/xml_exporter.py | 20 ++++++++++++++++++- .../xmodule/modulestore/xml_importer.py | 6 ++++++ common/lib/xmodule/xmodule/xml_module.py | 6 +++--- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 87a2943773..af62276ec4 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -1426,7 +1426,7 @@ def generate_export_course(request, org, course, name): logging.debug('root = {0}'.format(root_dir)) - export_to_xml(modulestore('direct'), contentstore(), loc, root_dir, name) + export_to_xml(modulestore('direct'), contentstore(), loc, root_dir, name, modulestore()) #filename = root_dir / name + '.tar.gz' logging.debug('tar file being generated at {0}'.format(export_file.name)) diff --git a/common/lib/xmodule/xmodule/modulestore/draft.py b/common/lib/xmodule/xmodule/modulestore/draft.py index 81f4da2780..6124d240a7 100644 --- a/common/lib/xmodule/xmodule/modulestore/draft.py +++ b/common/lib/xmodule/xmodule/modulestore/draft.py @@ -183,6 +183,10 @@ class DraftModuleStore(ModuleStoreBase): metadata.update(draft.metadata) metadata['published_date'] = tuple(datetime.utcnow().timetuple()) metadata['published_by'] = published_by_id + + if 'is_draft' in metadata: + del metadata['is_draft'] + super(DraftModuleStore, self).update_item(location, draft.definition.get('data', {})) super(DraftModuleStore, self).update_children(location, draft.definition.get('children', [])) super(DraftModuleStore, self).update_metadata(location, metadata) diff --git a/common/lib/xmodule/xmodule/modulestore/xml_exporter.py b/common/lib/xmodule/xmodule/modulestore/xml_exporter.py index 55844116c6..e8d3fb0f82 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_exporter.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_exporter.py @@ -5,7 +5,7 @@ from fs.osfs import OSFS from json import dumps -def export_to_xml(modulestore, contentstore, course_location, root_dir, course_dir): +def export_to_xml(modulestore, contentstore, course_location, root_dir, course_dir, draft_modulestore = None): course = modulestore.get_item(course_location) @@ -41,6 +41,24 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d policy = {'course/' + course.location.name: course.metadata} course_policy.write(dumps(policy)) + # export everything from the draft store, unfortunately this will create lots of duplicates + if draft_modulestore is not None: + draft_course = draft_modulestore.get_item(course_location) + draft_course_dir = export_fs.makeopendir('drafts') + xml = draft_course.export_to_xml(draft_course_dir) + with draft_course_dir.open('course.xml', 'w') as course_xml: + course_xml.write(xml) + + ''' + draft_items = modulestore.get_items([None, None, None, 'vertical', None, 'draft']) + logging.debug('draft_items = {0}'.format(draft_items)) + if len(draft_items) > 0: + + for draft_item in draft_items: + draft_item.export_to_xml(draft_items_dir) + #with draft_items_dir.open(draft_item.location.name + '.xml', 'w'): + ''' + 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) diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index 0b77900ae9..9fcd75d6f4 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -220,9 +220,15 @@ def import_from_xml(store, data_dir, course_dirs=None, # inherited metadata everywhere. store.update_metadata(module.location, dict(module.own_metadata)) + # now import any 'draft' items + import_course_draft(store, course_data_path, target_location_namespace) + return module_store, course_items +def import_course_draft(store, course_data_path, target_location_namespace): + pass + def remap_namespace(module, target_location_namespace): if target_location_namespace is None: return module diff --git a/common/lib/xmodule/xmodule/xml_module.py b/common/lib/xmodule/xmodule/xml_module.py index 64c3aabbcc..9081206491 100644 --- a/common/lib/xmodule/xmodule/xml_module.py +++ b/common/lib/xmodule/xmodule/xml_module.py @@ -105,8 +105,7 @@ class XmlDescriptor(XModuleDescriptor): 'name', 'slug') metadata_to_strip = ('data_dir', - # cdodge: @TODO: We need to figure out a way to export out 'tabs' and 'grading_policy' which is on the course - 'tabs', 'grading_policy', 'is_draft', 'published_by', 'published_date', + 'tabs', 'grading_policy', 'published_by', 'published_date', 'discussion_blackouts', 'testcenter_info', # VS[compat] -- remove the below attrs once everything is in the CMS 'course', 'org', 'url_name', 'filename') @@ -129,7 +128,8 @@ class XmlDescriptor(XModuleDescriptor): 'hide_progress_tab': bool_map, 'allow_anonymous': bool_map, 'allow_anonymous_to_peers': bool_map, - 'weight': int_map + 'weight': int_map, + 'is_draft': bool_map }