Created
June 26, 2013 15:51
-
-
Save hughes/5868597 to your computer and use it in GitHub Desktop.
Comparison of old vs new course pack import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trees = course_pack.trees.all().values_list('data', flat=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for module in course_pack_modules: | |
tree = Folder() | |
for item in course_pack_modules[module]: | |
item = item.cast() | |
#determine the parent to insert the item into; either a folder, or the tree itself | |
folder_name = folder_memberships.get(item.key_str) | |
if not folder_name: | |
#if item has no folder, parent is the tree | |
parent = tree | |
elif tree.get_item(folder_name): | |
#if folder already exists, get it | |
parent = tree.get_item(folder_name) | |
else: | |
#if folder does not yet exist, add it | |
parent = tree.initialize_type("folder", folder_name) | |
tree.add_item(parent) | |
#create and the item to the parent | |
tree_item = tree.initialize_type("item", item.tree_id()) | |
tree_item.title = item.display_name | |
parent.add_item(tree_item) | |
data[module] = tree.serialize() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment