Skip to content

Commit abb1d0e

Browse files
committed
Add example actions for the UK1841 form
1 parent b434f90 commit abb1d0e

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

Form/UK1841.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#
2+
# Gramps - a GTK+/GNOME based genealogy program
3+
#
4+
# Copyright (C) 2019 Steve Youngs
5+
#
6+
# This program is free software; you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation; either version 2 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program; if not, write to the Free Software
18+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
#
20+
21+
from gramps.gen.display.name import displayer as name_displayer
22+
from gramps.gen.lib import (Event, EventType, EventRef, EventRoleType,
23+
Person)
24+
25+
from actionbase import ActionBase
26+
27+
#------------------------------------------------------------------------
28+
#
29+
# Internationalisation
30+
#
31+
#------------------------------------------------------------------------
32+
from gramps.gen.const import GRAMPS_LOCALE as glocale
33+
try:
34+
_trans = glocale.get_addon_translator(__file__)
35+
except ValueError:
36+
_trans = glocale.translation
37+
38+
_ = _trans.gettext
39+
40+
class PrimaryNameCitation(ActionBase):
41+
def __init__(self):
42+
ActionBase.__init__(self)
43+
pass
44+
45+
def populate_model(self, db, citation, form_event, model):
46+
parent = model.append(None, (_("Add Primary Name citation"), None, None))
47+
for item in db.find_backlink_handles(form_event.get_handle(),
48+
include_classes=['Person']):
49+
handle = item[1]
50+
person = db.get_person_from_handle(handle)
51+
model.append(parent, (name_displayer.display(person), name_displayer.display(person),
52+
lambda db, trans, citation_handle = citation.handle, person_handle = person.handle: PrimaryNameCitation.command(db, trans, citation_handle, person_handle)))
53+
54+
def command(db, trans, citation_handle, person_handle):
55+
person = db.get_person_from_handle(person_handle)
56+
person.get_primary_name().add_citation(citation_handle)
57+
db.commit_person(person, trans)
58+
59+
class OccupationEvent(ActionBase):
60+
def __init__(self):
61+
ActionBase.__init__(self)
62+
pass
63+
64+
def populate_model(self, db, citation, form_event, model):
65+
parent = model.append(None, (_("Add Occupation event"), None, None))
66+
for item in db.find_backlink_handles(form_event.get_handle(),
67+
include_classes=['Person']):
68+
handle = item[1]
69+
person = db.get_person_from_handle(handle)
70+
for event_ref in person.get_event_ref_list():
71+
if event_ref.ref == form_event.get_handle():
72+
for attr in event_ref.get_attribute_list():
73+
if (attr.get_type() == "Occupation"): # Form specific _attribute name
74+
occupation = attr.get_value()
75+
if (occupation) :
76+
model.append(parent, (name_displayer.display(person), occupation,
77+
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)))

Form/actionbase.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,23 @@ class ActionBase():
3232
"""
3333
def __init__(self):
3434
pass
35+
36+
def AddEventToPerson(db, trans, person_handle, event_type, event_date_object, event_description, citation_handle, event_role_type):
37+
"""
38+
Add a new event to the specified person.
39+
"""
40+
event = Event()
41+
event.set_type(event_type)
42+
event.set_date_object(event_date_object)
43+
event.add_citation(citation_handle)
44+
event.set_description(event_description)
45+
46+
# add to the database
47+
db.add_event(event, trans)
48+
# Add new event reference to the Person record
49+
event_ref = EventRef()
50+
event_ref.ref = event.get_handle()
51+
event_ref.set_role(event_role_type)
52+
person = db.get_person_from_handle(person_handle)
53+
person.add_event_ref(event_ref)
54+
db.commit_person(person, trans)

0 commit comments

Comments
 (0)