def delete_note(db_handle: DbWriteBase, handle: str, trans: DbTxn) -> None: """Delete a note and its references.""" note = db_handle.get_note_from_handle(handle) ( person_list, family_list, event_list, place_list, source_list, citation_list, media_list, repo_list, ) = get_note_referents(handle, db_handle) note_handle = note.get_handle() for _handle in person_list: person = db_handle.get_person_from_handle(_handle) if person: person.remove_note(note_handle) db_handle.commit_person(person, trans) for _handle in family_list: family = db_handle.get_family_from_handle(_handle) if family: family.remove_note(note_handle) db_handle.commit_family(family, trans) for _handle in event_list: event = db_handle.get_event_from_handle(_handle) if event: event.remove_note(note_handle) db_handle.commit_event(event, trans) for _handle in place_list: place = db_handle.get_place_from_handle(_handle) if place: place.remove_note(note_handle) db_handle.commit_place(place, trans) for _handle in source_list: source = db_handle.get_source_from_handle(_handle) if source: source.remove_note(note_handle) db_handle.commit_source(source, trans) for _handle in citation_list: citation = db_handle.get_citation_from_handle(_handle) if citation: citation.remove_note(note_handle) db_handle.commit_citation(citation, trans) for _handle in media_list: media = db_handle.get_media_from_handle(_handle) if media: media.remove_note(note_handle) db_handle.commit_media(media, trans) for _handle in repo_list: repo = db_handle.get_repository_from_handle(_handle) if repo: repo.remove_note(note_handle) db_handle.commit_repository(repo, trans) db_handle.remove_note(note_handle, trans)
def delete_media(db_handle: DbWriteBase, handle: str, trans: DbTxn) -> None: """Delete an media object and its references.""" ( person_list, family_list, event_list, place_list, source_list, citation_list, ) = get_media_referents(handle, db_handle) for _handle in person_list: person = db_handle.get_person_from_handle(_handle) new_list = [ photo for photo in person.get_media_list() if photo.get_reference_handle() != handle ] person.set_media_list(new_list) db_handle.commit_person(person, trans) for _handle in family_list: family = db_handle.get_family_from_handle(_handle) new_list = [ photo for photo in family.get_media_list() if photo.get_reference_handle() != handle ] family.set_media_list(new_list) db_handle.commit_family(family, trans) for _handle in event_list: event = db_handle.get_event_from_handle(_handle) new_list = [ photo for photo in event.get_media_list() if photo.get_reference_handle() != handle ] event.set_media_list(new_list) db_handle.commit_event(event, trans) for _handle in place_list: place = db_handle.get_place_from_handle(_handle) new_list = [ photo for photo in place.get_media_list() if photo.get_reference_handle() != handle ] place.set_media_list(new_list) db_handle.commit_place(place, trans) for _handle in source_list: source = db_handle.get_source_from_handle(_handle) new_list = [ photo for photo in source.get_media_list() if photo.get_reference_handle() != handle ] source.set_media_list(new_list) db_handle.commit_source(source, trans) for _handle in citation_list: citation = db_handle.get_citation_from_handle(_handle) new_list = [ photo for photo in citation.get_media_list() if photo.get_reference_handle() != handle ] citation.set_media_list(new_list) db_handle.commit_citation(citation, trans) db_handle.remove_media(handle, trans)