def delete_event(db_handle: DbWriteBase, handle: str, trans: DbTxn) -> None: """Delete an event and its references.""" ev_handle_list = [handle] person_list = [ item[1] for item in db_handle.find_backlink_handles(handle, ["Person"]) ] family_list = [ item[1] for item in db_handle.find_backlink_handles(handle, ["Family"]) ] for person_handle in person_list: person = db_handle.get_person_from_handle(person_handle) person.remove_handle_references("Event", ev_handle_list) db_handle.commit_person(person, trans) for family_handle in family_list: family = db_handle.get_family_from_handle(family_handle) family.remove_handle_references("Event", ev_handle_list) db_handle.commit_family(family, trans) db_handle.remove_event(handle, trans)
def delete_tag(db_handle: DbWriteBase, handle: str, trans: DbTxn) -> None: """Delete a tag.""" fnc = { "Person": (db_handle.get_person_from_handle, db_handle.commit_person), "Family": (db_handle.get_family_from_handle, db_handle.commit_family), "Event": (db_handle.get_event_from_handle, db_handle.commit_event), "Place": (db_handle.get_place_from_handle, db_handle.commit_place), "Source": (db_handle.get_source_from_handle, db_handle.commit_source), "Citation": (db_handle.get_citation_from_handle, db_handle.commit_citation), "Repository": ( db_handle.get_repository_from_handle, db_handle.commit_repository, ), "Media": (db_handle.get_media_from_handle, db_handle.commit_media), "Note": (db_handle.get_note_from_handle, db_handle.commit_note), } links = db_handle.find_backlink_handles(handle) for classname, _handle in links: obj = fnc[classname][0](_handle) # get from handle obj.remove_tag(handle) fnc[classname][1](obj, trans) # commit db_handle.remove_tag(handle, trans)
def delete_repository(db_handle: DbWriteBase, handle: str, trans: DbTxn) -> None: """Delete a repository and its references.""" souce_list = [ item[1] for item in db_handle.find_backlink_handles(handle, ["Source"]) ] repos_handle_list = [handle] for _handle in souce_list: source = db_handle.get_source_from_handle(_handle) source.remove_repo_references(repos_handle_list) db_handle.commit_source(source, trans) db_handle.remove_repository(handle, trans)
def delete_citation(db_handle: DbWriteBase, handle: str, trans: DbTxn) -> None: """Delete an event and its references.""" ( person_list, family_list, event_list, place_list, source_list, media_list, repo_list, ) = get_citation_referents(handle, db_handle) citation = db_handle.get_citation_from_handle(handle) ctn_handle_list = [handle] for _handle in person_list: person = db_handle.get_person_from_handle(_handle) person.remove_citation_references(ctn_handle_list) db_handle.commit_person(person, trans) for _handle in family_list: family = db_handle.get_family_from_handle(_handle) family.remove_citation_references(ctn_handle_list) db_handle.commit_family(family, trans) for _handle in event_list: event = db_handle.get_event_from_handle(_handle) event.remove_citation_references(ctn_handle_list) db_handle.commit_event(event, trans) for _handle in place_list: place = db_handle.get_place_from_handle(_handle) place.remove_citation_references(ctn_handle_list) db_handle.commit_place(place, trans) for _handle in source_list: source = db_handle.get_source_from_handle(_handle) source.remove_citation_references(ctn_handle_list) db_handle.commit_source(source, trans) for _handle in media_list: media = db_handle.get_media_from_handle(_handle) media.remove_citation_references(ctn_handle_list) db_handle.commit_media(media, trans) for _handle in repo_list: repo = db_handle.get_repository_from_handle(_handle) repo.remove_citation_references(ctn_handle_list) db_handle.commit_repository(repo, trans) db_handle.remove_citation(citation.get_handle(), trans)
def delete_family(db_handle: DbWriteBase, handle: str, trans: DbTxn) -> None: """Delete a family and its references.""" return db_handle.remove_family_relationships(handle, trans=trans)
def delete_person(db_handle: DbWriteBase, handle: str, trans: DbTxn) -> None: """Delete an person and its references.""" person = db_handle.get_person_from_handle(handle) db_handle.delete_person_from_database(person, trans)
def delete_source(db_handle: DbWriteBase, handle: str, trans: DbTxn) -> None: """Delete a source and its references.""" # we can have: # object(CitationBase) -> Citation(source_handle) -> Source # We first have to remove the CitationBase references to the # Citation. Then we remove the Citations. (We don't need to # remove the source_handle references to the Source, because we are # removing the whole Citation). Then we can remove the Source (citation_list, citation_referents_list) = get_source_and_citation_referents( handle, db_handle) # citation_list is a tuple of lists. Only the first, for Citations, # exists. citation_list = citation_list[0] # (1) delete the references to the citation for (citation_handle, refs) in citation_referents_list: ( person_list, family_list, event_list, place_list, source_list, media_list, repo_list, ) = refs ctn_handle_list = [citation_handle] for _handle in person_list: person = db_handle.get_person_from_handle(_handle) person.remove_citation_references(ctn_handle_list) db_handle.commit_person(person, trans) for _handle in family_list: family = db_handle.get_family_from_handle(_handle) family.remove_citation_references(ctn_handle_list) db_handle.commit_family(family, trans) for _handle in event_list: event = db_handle.get_event_from_handle(_handle) event.remove_citation_references(ctn_handle_list) db_handle.commit_event(event, trans) for _handle in place_list: place = db_handle.get_place_from_handle(_handle) place.remove_citation_references(ctn_handle_list) db_handle.commit_place(place, trans) for _handle in source_list: source = db_handle.get_source_from_handle(_handle) source.remove_citation_references(ctn_handle_list) db_handle.commit_source(source, trans) for _handle in media_list: media = db_handle.get_media_from_handle(_handle) media.remove_citation_references(ctn_handle_list) db_handle.commit_media(media, trans) for _handle in repo_list: repo = db_handle.get_repository_from_handle(_handle) repo.remove_citation_references(ctn_handle_list) db_handle.commit_repository(repo, trans) for citation_handle in citation_list: db_handle.remove_citation(citation_handle, trans) db_handle.remove_source(handle, trans)
def delete_place(db_handle: DbWriteBase, handle: str, trans: DbTxn) -> None: """Delete a place and its references.""" person_list = [ item[1] for item in db_handle.find_backlink_handles(handle, ["Person"]) ] family_list = [ item[1] for item in db_handle.find_backlink_handles(handle, ["Family"]) ] event_list = [ item[1] for item in db_handle.find_backlink_handles(handle, ["Event"]) ] for _handle in person_list: person = db_handle.get_person_from_handle(_handle) person.remove_handle_references("Place", handle) db_handle.commit_person(person, trans) for _handle in family_list: family = db_handle.get_family_from_handle(_handle) family.remove_handle_references("Place", handle) db_handle.commit_family(family, trans) for _handle in event_list: event = db_handle.get_event_from_handle(_handle) event.remove_handle_references("Place", handle) db_handle.commit_event(event, trans) db_handle.remove_place(handle, trans)
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)
def __init__(self): DbReadBase.__init__(self) DbWriteBase.__init__(self) self._tables = { 'Person': { "handle_func": self.get_person_from_handle, "gramps_id_func": self.get_person_from_gramps_id, "class_func": gramps.gen.lib.Person, "cursor_func": self.get_person_cursor, "handles_func": self.get_person_handles, "iter_func": self.iter_people, }, 'Family': { "handle_func": self.get_family_from_handle, "gramps_id_func": self.get_family_from_gramps_id, "class_func": gramps.gen.lib.Family, "cursor_func": self.get_family_cursor, "handles_func": self.get_family_handles, "iter_func": self.iter_families, }, 'Source': { "handle_func": self.get_source_from_handle, "gramps_id_func": self.get_source_from_gramps_id, "class_func": gramps.gen.lib.Source, "cursor_func": self.get_source_cursor, "handles_func": self.get_source_handles, "iter_func": self.iter_sources, }, 'Citation': { "handle_func": self.get_citation_from_handle, "gramps_id_func": self.get_citation_from_gramps_id, "class_func": gramps.gen.lib.Citation, "cursor_func": self.get_citation_cursor, "handles_func": self.get_citation_handles, "iter_func": self.iter_citations, }, 'Event': { "handle_func": self.get_event_from_handle, "gramps_id_func": self.get_event_from_gramps_id, "class_func": gramps.gen.lib.Event, "cursor_func": self.get_event_cursor, "handles_func": self.get_event_handles, "iter_func": self.iter_events, }, 'Media': { "handle_func": self.get_object_from_handle, "gramps_id_func": self.get_object_from_gramps_id, "class_func": gramps.gen.lib.MediaObject, "cursor_func": self.get_media_cursor, "handles_func": self.get_media_object_handles, "iter_func": self.iter_media_objects, }, 'Place': { "handle_func": self.get_place_from_handle, "gramps_id_func": self.get_place_from_gramps_id, "class_func": gramps.gen.lib.Place, "cursor_func": self.get_place_cursor, "handles_func": self.get_place_handles, "iter_func": self.iter_places, }, 'Repository': { "handle_func": self.get_repository_from_handle, "gramps_id_func": self.get_repository_from_gramps_id, "class_func": gramps.gen.lib.Repository, "cursor_func": self.get_repository_cursor, "handles_func": self.get_repository_handles, "iter_func": self.iter_repositories, }, 'Note': { "handle_func": self.get_note_from_handle, "gramps_id_func": self.get_note_from_gramps_id, "class_func": gramps.gen.lib.Note, "cursor_func": self.get_note_cursor, "handles_func": self.get_note_handles, "iter_func": self.iter_notes, }, 'Tag': { "handle_func": self.get_tag_from_handle, "gramps_id_func": None, "class_func": gramps.gen.lib.Tag, "cursor_func": self.get_tag_cursor, "handles_func": self.get_tag_handles, "iter_func": self.iter_tags, }, } # skip GEDCOM cross-ref check for now: self.set_feature("skip-check-xref", True) self.dji = DjangoInterface() self.readonly = False self.db_is_open = True self.name_formats = [] self.bookmarks = Bookmarks() self.family_bookmarks = Bookmarks() self.event_bookmarks = Bookmarks() self.place_bookmarks = Bookmarks() self.citation_bookmarks = Bookmarks() self.source_bookmarks = Bookmarks() self.repo_bookmarks = Bookmarks() self.media_bookmarks = Bookmarks() self.note_bookmarks = Bookmarks() self.set_person_id_prefix('I%04d') self.set_object_id_prefix('O%04d') self.set_family_id_prefix('F%04d') self.set_citation_id_prefix('C%04d') self.set_source_id_prefix('S%04d') self.set_place_id_prefix('P%04d') self.set_event_id_prefix('E%04d') self.set_repository_id_prefix('R%04d') self.set_note_id_prefix('N%04d') # ---------------------------------- self.id_trans = DjangoTxn("ID Transaction", self, self.dji.Person) self.fid_trans = DjangoTxn("FID Transaction", self, self.dji.Family) self.pid_trans = DjangoTxn("PID Transaction", self, self.dji.Place) self.cid_trans = DjangoTxn("CID Transaction", self, self.dji.Citation) self.sid_trans = DjangoTxn("SID Transaction", self, self.dji.Source) self.oid_trans = DjangoTxn("OID Transaction", self, self.dji.Media) self.rid_trans = DjangoTxn("RID Transaction", self, self.dji.Repository) self.nid_trans = DjangoTxn("NID Transaction", self, self.dji.Note) self.eid_trans = DjangoTxn("EID Transaction", self, self.dji.Event) self.cmap_index = 0 self.smap_index = 0 self.emap_index = 0 self.pmap_index = 0 self.fmap_index = 0 self.lmap_index = 0 self.omap_index = 0 self.rmap_index = 0 self.nmap_index = 0 self.env = None self.person_map = {} self.family_map = {} self.place_map = {} self.citation_map = {} self.source_map = {} self.repository_map = {} self.note_map = {} self.media_map = {} self.event_map = {} self.metadata = {} self.name_group = {} self.undo_callback = None self.redo_callback = None self.undo_history_callback = None self.modified = 0 self.txn = DjangoTxn("DbDjango Transaction", self) self.transaction = None # Import cache for gedcom import, uses transactions, and # two step adding of objects. self.import_cache = {} self.use_import_cache = False self.use_db_cache = True