Skip to content

Commit

Permalink
Add example actions for the UK1841 form
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenyoungs committed Dec 29, 2019
1 parent b434f90 commit abb1d0e
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
77 changes: 77 additions & 0 deletions Form/UK1841.py
Original file line number Diff line number Diff line change
@@ -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)))
20 changes: 20 additions & 0 deletions Form/actionbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit abb1d0e

Please sign in to comment.