|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
19 | 19 | #
|
20 | 20 |
|
| 21 | +from gramps.gen.datehandler import displayer as date_displayer |
21 | 22 | from gramps.gen.display.name import displayer as name_displayer
|
22 |
| -from gramps.gen.lib import (Event, EventType, EventRef, EventRoleType, |
| 23 | +from gramps.gen.lib import (Date, Event, EventType, EventRef, EventRoleType, |
23 | 24 | Person)
|
24 | 25 |
|
25 |
| -from actionbase import ActionBase |
| 26 | +from actionbase import ActionBase, represents_int |
26 | 27 |
|
27 | 28 | #------------------------------------------------------------------------
|
28 | 29 | #
|
@@ -56,6 +57,44 @@ def command(db, trans, citation_handle, person_handle):
|
56 | 57 | person.get_primary_name().add_citation(citation_handle)
|
57 | 58 | db.commit_person(person, trans)
|
58 | 59 |
|
| 60 | +class BirthEvent(ActionBase): |
| 61 | + def __init__(self): |
| 62 | + ActionBase.__init__(self) |
| 63 | + pass |
| 64 | + |
| 65 | + def populate_model(self, db, citation, form_event, model): |
| 66 | + # if there is no date on the form, no actions can be performed |
| 67 | + if form_event.get_date_object(): |
| 68 | + parent = model.append(None, (_("Add Birth event"), None, None)) |
| 69 | + for item in db.find_backlink_handles(form_event.get_handle(), |
| 70 | + include_classes=['Person']): |
| 71 | + handle = item[1] |
| 72 | + person = db.get_person_from_handle(handle) |
| 73 | + for event_ref in person.get_event_ref_list(): |
| 74 | + if event_ref.ref == form_event.get_handle(): |
| 75 | + for attr in event_ref.get_attribute_list(): |
| 76 | + if (attr.get_type() == "Age"): # Form specific _attribute name |
| 77 | + age_string = attr.get_value() |
| 78 | + if age_string and represents_int(age_string): |
| 79 | + age = int(age_string) |
| 80 | + if age: |
| 81 | + birth_date = form_event.get_date_object() - age |
| 82 | + birth_date.make_vague() |
| 83 | + # Age was rounded down to the nearest five years for those aged 15 or over |
| 84 | + # In practice this rule was not always followed by enumerators |
| 85 | + if age < 15: |
| 86 | + # no adjustment required |
| 87 | + birth_date.set_modifier(Date.MOD_ABOUT) |
| 88 | + elif not birth_date.is_compound(): |
| 89 | + # in theory, birth_date will never be compound since 1841 census date was 1841-06-06. Let's handle it anyway. |
| 90 | + # create a compound range spanning the possible birth years |
| 91 | + birth_range = (birth_date - 5).get_dmy() + (False,) + birth_date.get_dmy() + (False,) |
| 92 | + birth_date.set(Date.QUAL_NONE, Date.MOD_RANGE, birth_date.get_calendar(), birth_range, newyear=birth_date.get_new_year()) |
| 93 | + birth_date.set_quality(Date.QUAL_CALCULATED) |
| 94 | + |
| 95 | + model.append(parent, (name_displayer.display(person), date_displayer.display(birth_date), |
| 96 | + lambda db, trans, citation_handle = citation.handle, person_handle = person.handle, birth_date_ = birth_date: ActionBase.AddEventToPerson(db, trans, person_handle, EventType.BIRTH, birth_date_, None, citation_handle, EventRoleType.PRIMARY))) |
| 97 | + |
59 | 98 | class OccupationEvent(ActionBase):
|
60 | 99 | def __init__(self):
|
61 | 100 | ActionBase.__init__(self)
|
|
0 commit comments