Commit 7a334c67 by Chris Dodge

go back to exporting draft/private verticals, but also set additional xml…

go back to exporting draft/private verticals, but also set additional xml attributes so that we can re-tie in the draft stuff into the sequence's children
parent 5bbfe870
...@@ -59,19 +59,15 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d ...@@ -59,19 +59,15 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d
'vertical', None, 'draft']) 'vertical', None, 'draft'])
if len(draft_verticals)>0: if len(draft_verticals)>0:
# now we have to go find every parent for each module and export from that point. We have draft_course_dir = export_fs.makeopendir('drafts')
# to initiate the export from the sequence since we need the child pointers to private
# verticals. These will get filtered out from the export of the non-draft store.
sequential_locs = []
for draft_vertical in draft_verticals: for draft_vertical in draft_verticals:
parent_locs = draft_modulestore.get_parent_locations(draft_vertical.location, course.location.course_id) parent_locs = draft_modulestore.get_parent_locations(draft_vertical.location, course.location.course_id)
if parent_locs[0] not in sequential_locs: logging.debug('parent_locs = {0}'.format(parent_locs))
sequential_locs.append(parent_locs[0]) draft_vertical.xml_attributes['parent_sequential_url'] = Location(parent_locs[0]).url()
sequential = modulestore.get_item(Location(parent_locs[0]))
draft_course_dir = export_fs.makeopendir('drafts') index = sequential.children.index(draft_vertical.location.url())
for sequential_loc in sequential_locs: draft_vertical.xml_attributes['index_in_children_list'] = str(index)
sequential = draft_modulestore.get_item(sequential_loc) draft_vertical.export_to_xml(draft_course_dir)
sequential.export_to_xml(draft_course_dir)
def export_extra_content(export_fs, modulestore, course_location, category_type, dirname, file_suffix=''): def export_extra_content(export_fs, modulestore, course_location, category_type, dirname, file_suffix=''):
......
...@@ -364,7 +364,7 @@ def import_course_draft(xml_module_store, store, course_data_path, static_conten ...@@ -364,7 +364,7 @@ def import_course_draft(xml_module_store, store, course_data_path, static_conten
) )
# now walk the /vertical directory where each file in there will be a draft copy of the Vertical # now walk the /vertical directory where each file in there will be a draft copy of the Vertical
for dirname, dirnames, filenames in os.walk(draft_dir + "/sequential"): for dirname, dirnames, filenames in os.walk(draft_dir + "/vertical"):
for filename in filenames: for filename in filenames:
module_path = os.path.join(dirname, filename) module_path = os.path.join(dirname, filename)
with open(module_path) as f: with open(module_path) as f:
...@@ -373,8 +373,30 @@ def import_course_draft(xml_module_store, store, course_data_path, static_conten ...@@ -373,8 +373,30 @@ def import_course_draft(xml_module_store, store, course_data_path, static_conten
descriptor = system.process_xml(xml) descriptor = system.process_xml(xml)
def _import_module(module): def _import_module(module):
if module.location.category != 'sequential': module.location = module.location._replace(revision='draft')
module.location = module.location._replace(revision='draft') # make sure our parent has us in its list of children
# this is to make sure private only verticals show up in the list of children since
# they would have been filtered out from the non-draft store export
if module.location.category == 'vertical':
module.location = module.location._replace(revision=None)
sequential_url = module.xml_attributes['parent_sequential_url']
index = int(module.xml_attributes['index_in_children_list'])
seq_location = Location(sequential_url)
# IMPORTANT: Be sure to update the sequential in the NEW namespace
seq_location = seq_location._replace(org=target_location_namespace.org,
course=target_location_namespace.course
)
sequential = store.get_item(seq_location)
if module.location.url() not in sequential.children:
sequential.children.insert(index, module.location.url())
store.update_children(sequential.location, sequential.children)
del module.xml_attributes['parent_sequential_url']
del module.xml_attributes['index_in_children_list']
import_module(module, store, course_data_path, static_content_store, allow_not_found=True) import_module(module, store, course_data_path, static_content_store, allow_not_found=True)
for child in module.get_children(): for child in module.get_children():
_import_module(child) _import_module(child)
...@@ -401,20 +423,20 @@ def remap_namespace(module, target_location_namespace): ...@@ -401,20 +423,20 @@ def remap_namespace(module, target_location_namespace):
# the caller passed in # the caller passed in
if module.location.category != 'course': if module.location.category != 'course':
module.location = module.location._replace(tag=target_location_namespace.tag, org=target_location_namespace.org, module.location = module.location._replace(tag=target_location_namespace.tag, org=target_location_namespace.org,
course=target_location_namespace.course) course=target_location_namespace.course)
else: else:
module.location = module.location._replace(tag=target_location_namespace.tag, org=target_location_namespace.org, module.location = module.location._replace(tag=target_location_namespace.tag, org=target_location_namespace.org,
course=target_location_namespace.course, name=target_location_namespace.name) course=target_location_namespace.course, name=target_location_namespace.name)
# then remap children pointers since they too will be re-namespaced # then remap children pointers since they too will be re-namespaced
if hasattr(module,'children'): if hasattr(module, 'children'):
children_locs = module.children children_locs = module.children
if children_locs is not None and children_locs != []: if children_locs is not None and children_locs != []:
new_locs = [] new_locs = []
for child in children_locs: for child in children_locs:
child_loc = Location(child) child_loc = Location(child)
new_child_loc = child_loc._replace(tag=target_location_namespace.tag, org=target_location_namespace.org, new_child_loc = child_loc._replace(tag=target_location_namespace.tag, org=target_location_namespace.org,
course=target_location_namespace.course) course=target_location_namespace.course)
new_locs.append(new_child_loc.url()) new_locs.append(new_child_loc.url())
...@@ -429,7 +451,7 @@ def allowed_metadata_by_category(category): ...@@ -429,7 +451,7 @@ def allowed_metadata_by_category(category):
'vertical': [], 'vertical': [],
'chapter': ['start'], 'chapter': ['start'],
'sequential': ['due', 'format', 'start', 'graded'] 'sequential': ['due', 'format', 'start', 'graded']
}.get(category,['*']) }.get(category, ['*'])
def check_module_metadata_editability(module): def check_module_metadata_editability(module):
......
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