def __init__(self, database, namespace, locale=glocale): """Initialize sort class.""" self.database = database self.locale = locale self.name_display = NameDisplay(xlocale=self.locale) self.place_display = PlaceDisplay() self.namespace = namespace self.query_method = self.database.method("get_%s_from_handle", self.namespace)
def set_locale(self, language): """ Set the translator to one selected with stdoptions.add_localization_option(). """ if language == GrampsLocale.DEFAULT_TRANSLATION_STR: language = None locale = GrampsLocale(lang=language) self._ = locale.translation.gettext self._get_date = locale.get_date self._get_type = locale.get_type self._ldd = locale.date_displayer self._name_display = NameDisplay(locale) # a legacy/historical name self._name_display.set_name_format(self.database.name_formats) fmt_default = config.get('preferences.name-format') self._name_display.set_default_format(fmt_default) return locale
"""Gramps utility functions.""" from typing import List, Optional from gramps.gen.const import GRAMPS_LOCALE from gramps.gen.db.base import DbReadBase from gramps.gen.display.name import NameDisplay from gramps.gen.errors import HandleError from gramps.gen.lib import Event, Person from gramps.gen.lib.primaryobj import BasicPrimaryObject as GrampsObject from gramps_webapi.types import GrampsId, Handle nd = NameDisplay() dd = GRAMPS_LOCALE.date_displayer def get_event_date_from_handle(db: DbReadBase, handle: Handle) -> Optional[str]: """Return a formatted date for the event.""" try: date = db.get_event_from_handle(handle).get_date_object() except AttributeError: return None return dd.display(date) or None def get_event_place_from_handle(db: DbReadBase, handle: Handle) -> Optional[GrampsId]: """Get an event's place.""" return get_event_place_grampsid(db, db.get_event_from_handle(handle))
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # Gramps imports: from gramps.gen.lib.person import Person from gramps.gen.display.name import NameDisplay # Gramps Connect imports: from .forms import Form # Globals: nd = NameDisplay().display class PersonForm(Form): """ A form for listing, viewing, and editing a Person object. """ _class = Person view = "person" tview = "People" # Fields for editor: edit_fields = [ "primary_name.type", "primary_name.title", "primary_name.nick",
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