def update_family_update_refs( db_handle: DbWriteBase, obj_old: Family, obj: Family, trans: DbTxn, ) -> None: """Update the `family_list` and `parent_family_list` of family members. Case where the family was modified. """ _fix_parent_handles( db_handle, obj, obj_old.get_father_handle(), obj.get_father_handle(), trans ) _fix_parent_handles( db_handle, obj, obj_old.get_mother_handle(), obj.get_mother_handle(), trans ) # fix child handles orig_set = set(r.ref for r in obj_old.get_child_ref_list()) new_set = set(r.ref for r in obj.get_child_ref_list()) # remove the family from children which have been removed for ref in orig_set - new_set: person = db_handle.get_person_from_handle(ref) person.remove_parent_family_handle(obj.handle) db_handle.commit_person(person, trans) # add the family to children which have been added for ref in new_set - orig_set: person = db_handle.get_person_from_handle(ref) person.add_parent_family_handle(obj.handle) db_handle.commit_person(person, trans)
def _get_parent(self, person, father): """ Get the father of the family if father == True, otherwise mother """ if person: parent_handle_list = person.get_parent_family_handle_list() if parent_handle_list: family_id = parent_handle_list[0] family = self.dbstate.db.get_family_from_handle(family_id) if family: if father: person_handle = Family.get_father_handle(family) else: person_handle = Family.get_mother_handle(family) if person_handle: fct = self.dbstate.db.get_person_from_handle return fct(person_handle) return None
def add_family_update_refs( db_handle: DbWriteBase, obj: Family, trans: DbTxn, ) -> None: """Update the `family_list` and `parent_family_list` of family members. Case where the family is new. """ # add family handle to parents for handle in [obj.get_father_handle(), obj.get_mother_handle()]: if handle: parent = db_handle.get_person_from_handle(handle) parent.add_family_handle(obj.handle) db_handle.commit_person(parent, trans) # for each child, add the family handle to the child for ref in obj.get_child_ref_list(): child = db_handle.get_person_from_handle(ref.ref) child.add_parent_family_handle(obj.handle) db_handle.commit_person(child, trans)