Skip to content

Commit 1430d27

Browse files
committed
New action: AlternateName which adds an alternate name to a Person on the form
1 parent 74ffe88 commit 1430d27

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Form/UK1841.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from gramps.gen.display.name import displayer as name_displayer
2929
from gramps.gen.display.place import displayer as place_displayer
3030
from gramps.gen.lib import (Date, Event, EventType, EventRef, EventRoleType,
31-
Person)
31+
Name, Person)
3232
from gramps.gen.utils.db import get_participant_from_event
3333

3434
#------------------------------------------------------------------------
@@ -70,6 +70,28 @@ def command(dbstate, uistate, track, citation_handle, person_handle):
7070
with DbTxn(_("Add Person (%s)") % name_displayer.display(person), db) as trans:
7171
db.commit_person(person, trans)
7272

73+
class AlternateName(ActionBase):
74+
def __init__(self):
75+
ActionBase.__init__(self)
76+
77+
def get_actions(self, dbstate, citation, form_event):
78+
db = dbstate.db
79+
actions = []
80+
for (person, attr) in ActionBase.get_form_person_attr(db, form_event.get_handle(), 'Name'):
81+
alternate = Name()
82+
alternate.set_first_name(attr.get_value())
83+
alternate.add_citation(citation.handle)
84+
actions.append((name_displayer.display(person), attr.get_value(),
85+
lambda dbstate, uistate, track, person_handle = person.handle, alternate_ = alternate: AlternateName.command(dbstate, uistate, track, person_handle, alternate_)))
86+
return (_("Add alternate name"), actions)
87+
88+
def command(dbstate, uistate, track, person_handle, alternate):
89+
db = dbstate.db
90+
person = db.get_person_from_handle(person_handle)
91+
person.add_alternate_name(alternate)
92+
with DbTxn(_("Add Person (%s)") % name_displayer.display(person), db) as trans:
93+
db.commit_person(person, trans)
94+
7395
class BirthEvent(ActionBase):
7496
def __init__(self):
7597
ActionBase.__init__(self)

0 commit comments

Comments
 (0)