Skip to content

Instantly share code, notes, and snippets.

@hughes
Created June 26, 2013 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hughes/5868597 to your computer and use it in GitHub Desktop.
Save hughes/5868597 to your computer and use it in GitHub Desktop.
Comparison of old vs new course pack import
trees = course_pack.trees.all().values_list('data', flat=True)
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