def delete_course(modulestore, contentstore, source_location, commit=False): # first check to see if the modulestore is Mongo backed if not isinstance(modulestore, MongoModuleStore): raise Exception("Expected a MongoModuleStore in the runtime. Aborting....") # check to see if the source course is actually there if not modulestore.has_item(source_location): raise Exception("Cannot find a course at {0}. Aborting".format(source_location)) # first delete all of the thumbnails thumbs = contentstore.get_all_content_thumbnails_for_course(source_location) for thumb in thumbs: thumb_loc = Location(thumb["_id"]) id = StaticContent.get_id_from_location(thumb_loc) print "Deleting {0}...".format(id) if commit: contentstore.delete(id) # then delete all of the assets assets = contentstore.get_all_content_for_course(source_location) for asset in assets: asset_loc = Location(asset["_id"]) id = StaticContent.get_id_from_location(asset_loc) print "Deleting {0}...".format(id) if commit: contentstore.delete(id) # then delete all course modules modules = modulestore.get_items([source_location.tag, source_location.org, source_location.course, None, None, None]) course_module = None for module in modules: if module.category != 'course': # save deleting the course module for last print "Deleting {0}...".format(module.location) if commit: modulestore.delete_item(module.location) else: course_module = module if course_module: modulestore.delete_item(course_module.location) # finally delete the top-level course module itself print "Deleting {0}...".format(source_location) if commit: modulestore.delete_item(source_location) return True
def delete_course(modulestore, contentstore, source_location, commit=False): # first check to see if the modulestore is Mongo backed if not isinstance(modulestore, MongoModuleStore): raise Exception( "Expected a MongoModuleStore in the runtime. Aborting....") # check to see if the source course is actually there if not modulestore.has_item(source_location): raise Exception( "Cannot find a course at {0}. Aborting".format(source_location)) # first delete all of the thumbnails thumbs = contentstore.get_all_content_thumbnails_for_course( source_location) for thumb in thumbs: thumb_loc = Location(thumb["_id"]) id = StaticContent.get_id_from_location(thumb_loc) print "Deleting {0}...".format(id) if commit: contentstore.delete(id) # then delete all of the assets assets = contentstore.get_all_content_for_course(source_location) for asset in assets: asset_loc = Location(asset["_id"]) id = StaticContent.get_id_from_location(asset_loc) print "Deleting {0}...".format(id) if commit: contentstore.delete(id) # then delete all course modules modules = modulestore.get_items([ source_location.tag, source_location.org, source_location.course, None, None, None ]) for module in modules: if module.category != 'course': # save deleting the course module for last print "Deleting {0}...".format(module.location) if commit: modulestore.delete_item(module.location) # finally delete the top-level course module itself print "Deleting {0}...".format(source_location) if commit: modulestore.delete_item(source_location) return True
def _delete_assets(contentstore, assets, commit): """ This helper method will enumerate through a list of assets and delete them """ for asset in assets: asset_loc = Location(asset["_id"]) id = StaticContent.get_id_from_location(asset_loc) logging.warning("Deleting {0}...".format(id)) if commit: contentstore.delete(id)
def _delete_assets(contentstore, assets, commit): """ This helper method will enumerate through a list of assets and delete them """ for asset in assets: asset_loc = Location(asset["_id"]) id = StaticContent.get_id_from_location(asset_loc) logging.warning("Deleting {0}...".format(id)) if commit: contentstore.delete(id)
def _clear_assets(location): store = contentstore() content_location = StaticContent.compute_location( location.org, location.course, location.name ) assets, __ = store.get_all_content_for_course(content_location) for asset in assets: asset_location = Location(asset["_id"]) id = StaticContent.get_id_from_location(asset_location) store.delete(id)
def _clear_assets(location): store = contentstore() content_location = StaticContent.compute_location(location.org, location.course, location.name) assets, __ = store.get_all_content_for_course(content_location) for asset in assets: asset_location = Location(asset["_id"]) id = StaticContent.get_id_from_location(asset_location) store.delete(id)
def empty_asset_trashcan(course_locs): ''' This method will hard delete all assets (optionally within a course_id) from the trashcan ''' store = contentstore('trashcan') for course_loc in course_locs: # first delete all of the thumbnails thumbs = store.get_all_content_thumbnails_for_course(course_loc) for thumb in thumbs: thumb_loc = Location(thumb["_id"]) id = StaticContent.get_id_from_location(thumb_loc) print "Deleting {0}...".format(id) store.delete(id) # then delete all of the assets assets = store.get_all_content_for_course(course_loc) for asset in assets: asset_loc = Location(asset["_id"]) id = StaticContent.get_id_from_location(asset_loc) print "Deleting {0}...".format(id) store.delete(id)
def get_id(self): return StaticContent.get_id_from_location(self.location)
def get_id(self): return StaticContent.get_id_from_location(self.location)