|
| 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))) |
0 commit comments