'Delete an item from this modulestore.
The method determines which revisions to delete. It disconnects and deletes the subtree.
In general, it assumes deletes only occur on drafts except for direct_only. The only exceptions
are internal calls like deleting orphans (during publishing as well as from delete_orphan view).
To indicate that all versions should be deleted, pass the keyword revision=ModuleStoreEnum.RevisionOption.all.
* Deleting a DIRECT_ONLY_CATEGORIES block, deletes both draft and published children and removes from parent.
* Deleting a specific version of block whose parent is of DIRECT_ONLY_CATEGORIES, only removes it from parent if
the other version of the block does not exist. Deletes only children of same version.
* Other deletions remove from parent of same version and subtree of same version
Args:
location: UsageKey of the item to be deleted
user_id: id of the user deleting the item
revision:
None - deletes the item and its subtree, and updates the parents per description above
ModuleStoreEnum.RevisionOption.published_only - removes only Published versions
ModuleStoreEnum.RevisionOption.all - removes both Draft and Published parents
currently only provided by contentstore.views.item.orphan_handler
Otherwise, raises a ValueError.'

def delete_item(self, location, user_id, revision=None, **kwargs):

    self._verify_branch_setting(ModuleStoreEnum.Branch.draft_preferred)
    _verify_revision_is_published(location)
    is_item_direct_only = (location.category in DIRECT_ONLY_CATEGORIES)
    if (is_item_direct_only or (revision == ModuleStoreEnum.RevisionOption.published_only)):
        parent_revision = MongoRevisionKey.published
    elif (revision == ModuleStoreEnum.RevisionOption.all):
        parent_revision = ModuleStoreEnum.RevisionOption.all
    else:
        parent_revision = MongoRevisionKey.draft
    parent_locations = self._get_raw_parent_locations(location, key_revision=parent_revision)
    if (not parent_locations):
        parent_locations = self._get_raw_parent_locations(location, key_revision=MongoRevisionKey.published)
        if parent_locations:
            draft_parent = self.convert_to_draft(parent_locations[0], user_id)
            parent_locations = [draft_parent.location]
    for parent_location in parent_locations:
        if ((not is_item_direct_only) and (parent_location.category in DIRECT_ONLY_CATEGORIES)):
            query = location.to_deprecated_son(prefix='_id.')
            del query['_id.revision']
            if (self.collection.find(query).count() > 1):
                continue
        parent_block = super(DraftModuleStore, self).get_item(parent_location)
        parent_block.children.remove(location)
        parent_block.location = parent_location
        self.update_item(parent_block, user_id, child_update=True)
    self._flag_publish_event(location.course_key)
    if (is_item_direct_only or (revision == ModuleStoreEnum.RevisionOption.all)):
        as_functions = [as_draft, as_published]
    elif (revision == ModuleStoreEnum.RevisionOption.published_only):
        as_functions = [as_published]
    elif (revision is None):
        as_functions = [as_draft]
    else:
        raise UnsupportedRevisionError([None, ModuleStoreEnum.RevisionOption.published_only, ModuleStoreEnum.RevisionOption.all])
    self._delete_subtree(location, as_functions)
