def object_extend(self, obj: Person, args: Dict) -> Person: """Extend person attributes as needed.""" db_handle = self.db_handle if "profile" in args: obj.profile = get_person_profile_for_object(db_handle, obj, with_family=True, with_events=True) if "extend" in args: obj.extended = get_extended_attributes(db_handle, obj, args) if "all" in args["extend"] or "families" in args["extend"]: obj.extended["families"] = [ get_family_by_handle(db_handle, handle) for handle in obj.family_list ] if "all" in args["extend"] or "parent_families" in args["extend"]: obj.extended["parent_families"] = [ get_family_by_handle(db_handle, handle) for handle in obj.parent_family_list ] if "all" in args["extend"] or "primary_parent_family" in args[ "extend"]: obj.extended["primary_parent_family"] = get_family_by_handle( db_handle, obj.get_main_parents_family_handle()) return obj
def get_person_profile_for_object( db_handle: DbReadBase, person: Person, with_family: bool = True, with_events: bool = True, ) -> Person: """Get person profile given a Person.""" profile = { "handle": person.handle, "sex": get_sex_profile(person), "birth": get_birth_profile(db_handle, person), "death": get_death_profile(db_handle, person), "name_given": nd.display_given(person), "name_surname": person.primary_name.get_surname(), } if with_family: primary_parent_family_handle = person.get_main_parents_family_handle() profile["primary_parent_family"] = get_family_profile_for_handle( db_handle, primary_parent_family_handle) profile["other_parent_families"] = [] for handle in person.parent_family_list: if handle != primary_parent_family_handle: profile["other_parent_families"].append( get_family_profile_for_handle(db_handle, handle)) profile["families"] = [ get_family_profile_for_handle(db_handle, handle) for handle in person.family_list ] if with_events: profile["events"] = [ get_event_profile_for_handle(db_handle, event_ref.ref) for event_ref in person.event_ref_list ] return profile
def get_parents_grampsids(db: DbReadBase, person: Person) -> Optional[GrampsId]: """Get the Gramps IDs of the family's parents.""" handle = person.get_main_parents_family_handle() try: return db.get_family_from_handle(handle).gramps_id except HandleError: return None
def get_person_profile_for_object(db_handle: DbReadBase, person: Person, args: List, locale: GrampsLocale = glocale) -> Person: """Get person profile given a Person.""" options = [] if "all" in args or "ratings" in args: options.append("ratings") name_display = NameDisplay(xlocale=locale) birth, birth_event = get_birth_profile(db_handle, person, args=options, locale=locale) death, death_event = get_death_profile(db_handle, person, args=options, locale=locale) if "all" in args or "age" in args: options.append("age") if birth_event is not None: birth["age"] = locale.translation.sgettext("0 days") if death_event is not None: death["age"] = (Span(birth_event.date, death_event.date).format( precision=3, dlocale=locale).strip("()")) profile = { "handle": person.handle, "gramps_id": person.gramps_id, "sex": get_sex_profile(person), "birth": birth, "death": death, "name_given": name_display.display_given(person), "name_surname": person.primary_name.get_surname(), } if "all" in args or "span" in args: options.append("span") if "all" in args or "events" in args: options.append("events") if "age" not in args and "all" not in args: birth_event = None profile["events"] = [ get_event_profile_for_handle( db_handle, event_ref.ref, args=options, base_event=birth_event, label="age", locale=locale, role=locale.translation.sgettext( event_ref.get_role().xml_str()), ) for event_ref in person.event_ref_list ] if "all" in args or "families" in args: primary_parent_family_handle = person.get_main_parents_family_handle() profile["primary_parent_family"] = get_family_profile_for_handle( db_handle, primary_parent_family_handle, options, locale=locale) profile["other_parent_families"] = [] for handle in person.parent_family_list: if handle != primary_parent_family_handle: profile["other_parent_families"].append( get_family_profile_for_handle(db_handle, handle, options, locale=locale)) profile["families"] = [ get_family_profile_for_handle(db_handle, handle, options, locale=locale) for handle in person.family_list ] return profile