From abb1d0e9ab27af79ccbd94a95ec0d7d51a6e84a9 Mon Sep 17 00:00:00 2001 From: Steve Youngs Date: Sun, 29 Dec 2019 17:02:49 +0000 Subject: [PATCH] Add example actions for the UK1841 form --- Form/UK1841.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++ Form/actionbase.py | 20 ++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 Form/UK1841.py diff --git a/Form/UK1841.py b/Form/UK1841.py new file mode 100644 index 000000000..d8f6413e4 --- /dev/null +++ b/Form/UK1841.py @@ -0,0 +1,77 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2019 Steve Youngs +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# 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. +# + +from gramps.gen.display.name import displayer as name_displayer +from gramps.gen.lib import (Event, EventType, EventRef, EventRoleType, + Person) + +from actionbase import ActionBase + +#------------------------------------------------------------------------ +# +# Internationalisation +# +#------------------------------------------------------------------------ +from gramps.gen.const import GRAMPS_LOCALE as glocale +try: + _trans = glocale.get_addon_translator(__file__) +except ValueError: + _trans = glocale.translation + +_ = _trans.gettext + +class PrimaryNameCitation(ActionBase): + def __init__(self): + ActionBase.__init__(self) + pass + + def populate_model(self, db, citation, form_event, model): + parent = model.append(None, (_("Add Primary Name citation"), None, None)) + for item in db.find_backlink_handles(form_event.get_handle(), + include_classes=['Person']): + handle = item[1] + person = db.get_person_from_handle(handle) + model.append(parent, (name_displayer.display(person), name_displayer.display(person), + lambda db, trans, citation_handle = citation.handle, person_handle = person.handle: PrimaryNameCitation.command(db, trans, citation_handle, person_handle))) + + def command(db, trans, citation_handle, person_handle): + person = db.get_person_from_handle(person_handle) + person.get_primary_name().add_citation(citation_handle) + db.commit_person(person, trans) + +class OccupationEvent(ActionBase): + def __init__(self): + ActionBase.__init__(self) + pass + + def populate_model(self, db, citation, form_event, model): + parent = model.append(None, (_("Add Occupation event"), None, None)) + for item in db.find_backlink_handles(form_event.get_handle(), + include_classes=['Person']): + handle = item[1] + person = db.get_person_from_handle(handle) + for event_ref in person.get_event_ref_list(): + if event_ref.ref == form_event.get_handle(): + for attr in event_ref.get_attribute_list(): + if (attr.get_type() == "Occupation"): # Form specific _attribute name + occupation = attr.get_value() + if (occupation) : + model.append(parent, (name_displayer.display(person), occupation, + lambda db, trans, citation_handle = citation.handle, person_handle = person.handle, occupation_ = occupation: ActionBase.AddEventToPerson(db, trans, person_handle, EventType.OCCUPATION, form_event.get_date_object(), occupation_, citation_handle, EventRoleType.PRIMARY))) diff --git a/Form/actionbase.py b/Form/actionbase.py index e44224d04..0f4b2acea 100644 --- a/Form/actionbase.py +++ b/Form/actionbase.py @@ -32,3 +32,23 @@ class ActionBase(): """ def __init__(self): pass + + def AddEventToPerson(db, trans, person_handle, event_type, event_date_object, event_description, citation_handle, event_role_type): + """ + Add a new event to the specified person. + """ + event = Event() + event.set_type(event_type) + event.set_date_object(event_date_object) + event.add_citation(citation_handle) + event.set_description(event_description) + + # add to the database + db.add_event(event, trans) + # Add new event reference to the Person record + event_ref = EventRef() + event_ref.ref = event.get_handle() + event_ref.set_role(event_role_type) + person = db.get_person_from_handle(person_handle) + person.add_event_ref(event_ref) + db.commit_person(person, trans)