def get_event_place_grampsid(db: DbReadBase, event: Event) -> Optional[GrampsId]: """Get the event's place.""" try: return db.get_place_from_handle(event.place).gramps_id except (HandleError, AttributeError): return None
def get_place_by_handle(db_handle: DbReadBase, handle: Handle) -> Union[Place, Dict]: """Safe get place by handle.""" try: return db_handle.get_place_from_handle(handle) except HandleError: return {}
def get_place_by_handle(db_handle: DbReadBase, handle: Handle) -> Optional[Place]: """Safe get place by handle.""" try: return db_handle.get_place_from_handle(handle) except HandleError: return None
def get_place_profile_for_object( db_handle: DbReadBase, place: Place, locale: GrampsLocale = glocale, parent_places: bool = True, ) -> Dict[str, Any]: """Get place profile given a Place.""" latitude, longitude = conv_lat_lon(place.lat, place.long, format="D.D8") profile = { "gramps_id": place.gramps_id, "type": _format_place_type(place.get_type(), locale=locale), "name": place.get_name().value, "alternate_names": [place_name.value for place_name in place.get_alternative_names()], "lat": float(latitude) if (latitude and longitude) else None, "long": float(longitude) if (latitude and longitude) else None, } if parent_places: parent_places_handles = [] _place = place handle = None while True: for placeref in _place.get_placeref_list(): handle = placeref.ref break if handle is None or handle in parent_places_handles: break _place = db_handle.get_place_from_handle(handle) if _place is None: break parent_places_handles.append(handle) profile["parent_places"] = [ get_place_profile_for_object( db_handle=db_handle, place=db_handle.get_place_from_handle(parent_place), locale=locale, parent_places=False, ) for parent_place in parent_places_handles ] return profile