Skip to content

Commit c1919d4

Browse files
committed
Initial attempt at adding Birth events from 1841 census
1 parent 8602b8f commit c1919d4

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

Form/UK1841.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1919
#
2020

21+
from gramps.gen.datehandler import displayer as date_displayer
2122
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,
2324
Person)
2425

25-
from actionbase import ActionBase
26+
from actionbase import ActionBase, represents_int
2627

2728
#------------------------------------------------------------------------
2829
#
@@ -56,6 +57,44 @@ def command(db, trans, citation_handle, person_handle):
5657
person.get_primary_name().add_citation(citation_handle)
5758
db.commit_person(person, trans)
5859

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+
5998
class OccupationEvent(ActionBase):
6099
def __init__(self):
61100
ActionBase.__init__(self)

Form/actionbase.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,13 @@ def AddEventToPerson(db, trans, person_handle, event_type, event_date_object, ev
5252
person = db.get_person_from_handle(person_handle)
5353
person.add_event_ref(event_ref)
5454
db.commit_person(person, trans)
55+
56+
def represents_int(s):
57+
"""
58+
return True iff s is convertable to an int, False otherwise
59+
"""
60+
try:
61+
int(s)
62+
return True
63+
except ValueError:
64+
return False

0 commit comments

Comments
 (0)