def get_age(self, start_date: str, date: str): """Return calculated age or empty string otherwise.""" age = "" if start_date: span = Span(start_date, date) if span.is_valid(): age = str( span.format(precision=self.precision, dlocale=self.locale).strip("()")) return age
def get_event_profile_for_object( db_handle: DbReadBase, event: Event, args: List, base_event: Union[Event, None] = None, label: str = "span", locale: GrampsLocale = glocale, role: Optional[str] = None, ) -> Dict: """Get event profile given an Event.""" result = { "type": locale.translation.sgettext(event.type.xml_str()), "date": locale.date_displayer.display(event.date), "place": pd.display_event(db_handle, event), } if role is not None: result["role"] = role if "all" in args or "participants" in args: result["participants"] = get_event_participants_for_handle( db_handle, event.handle, locale=locale) if "all" in args or "ratings" in args: count, confidence = get_rating(db_handle, event) result["citations"] = count result["confidence"] = confidence if base_event is not None: result[label] = (Span(base_event.date, event.date).format(precision=3, dlocale=locale).strip("()")) return result
def get(self, args: Dict, handle1: Handle, handle2: Handle) -> Response: """Get the time span between two event dates.""" try: event1 = self.db_handle.get_event_from_handle(handle1) event2 = self.db_handle.get_event_from_handle(handle2) except HandleError: abort(404) locale = get_locale_for_language(args["locale"], default=True) span = (Span(event1.date, event2.date).format(precision=args["precision"], as_age=args["as_age"], dlocale=locale).strip("()")) return self.response(200, {"span": str(span)})
def get_family_profile_for_object(db_handle: DbReadBase, family: Family, args: List, locale: GrampsLocale = glocale) -> Family: """Get family profile given a Family.""" options = [] if "all" in args or "ratings" in args: options.append("ratings") marriage, marriage_event = get_marriage_profile(db_handle, family, args=options, locale=locale) divorce, divorce_event = get_divorce_profile(db_handle, family, args=options, locale=locale) if "all" in args or "span" in args: if marriage_event is not None: marriage["span"] = locale.translation.sgettext("0 days") if divorce_event is not None: divorce["span"] = (Span(marriage_event.date, divorce_event.date).format( precision=3, dlocale=locale).strip("()")) if "all" in args or "age" in args: options.append("age") profile = { "handle": family.handle, "gramps_id": family.gramps_id, "father": get_person_profile_for_handle(db_handle, family.father_handle, options, locale=locale), "mother": get_person_profile_for_handle(db_handle, family.mother_handle, options, locale=locale), "relationship": locale.translation.sgettext(family.type.xml_str()), "marriage": marriage, "divorce": divorce, "children": [ get_person_profile_for_handle(db_handle, child_ref.ref, options, locale=locale) for child_ref in family.child_ref_list ], } if profile["father"]: if profile["father"]["name_surname"] or profile["father"]["name_given"]: profile["family_surname"] = profile["father"]["name_surname"] elif profile["mother"]: profile["family_surname"] = profile["mother"]["name_surname"] elif profile["mother"]: profile["family_surname"] = profile["mother"]["name_surname"] else: profile["family_surname"] = "" if "all" in args or "events" in args: if "span" not in args and "all" not in args: marriage_event = None profile["events"] = [ get_event_profile_for_handle( db_handle, event_ref.ref, args=options, base_event=marriage_event, label="span", locale=locale, ) for event_ref in family.event_ref_list ] return profile
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