def _delete_orphans(course_usage_key, user_id, commit=False):
 store = modulestore()
 items = store.get_orphans(course_usage_key)
 branch = course_usage_key.branch
 if commit:
  with store.bulk_operations(course_usage_key):
   for itemloc in items:
    revision = ModuleStoreEnum.RevisionOption.all
    if (branch == ModuleStoreEnum.BranchName.published):
     revision = ModuleStoreEnum.RevisionOption.published_only
    store.delete_item(itemloc, user_id, revision=revision)
 return [unicode(item) for item in items]

def _delete_orphans ( course_usage_key , user_id , commit = False ) : store = modulestore ( ) items = store . get_orphans ( course_usage_key ) branch = course_usage_key . branch if commit : with store . bulk_operations ( course_usage_key ) : for itemloc in items : revision = ModuleStoreEnum . RevisionOption . all if ( branch == ModuleStoreEnum . BranchName . published ) : revision = ModuleStoreEnum . RevisionOption . published_only store . delete_item ( itemloc , user_id , revision = revision ) return [ unicode ( item ) for item in items ]
helper function to delete orphans for a given course .