Skip to content

Commit

Permalink
Initial attempt at adding Birth events from 1841 census
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenyoungs committed Dec 29, 2019
1 parent 8602b8f commit c1919d4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
43 changes: 41 additions & 2 deletions Form/UK1841.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

from gramps.gen.datehandler import displayer as date_displayer
from gramps.gen.display.name import displayer as name_displayer
from gramps.gen.lib import (Event, EventType, EventRef, EventRoleType,
from gramps.gen.lib import (Date, Event, EventType, EventRef, EventRoleType,
Person)

from actionbase import ActionBase
from actionbase import ActionBase, represents_int

#------------------------------------------------------------------------
#
Expand Down Expand Up @@ -56,6 +57,44 @@ def command(db, trans, citation_handle, person_handle):
person.get_primary_name().add_citation(citation_handle)
db.commit_person(person, trans)

class BirthEvent(ActionBase):
def __init__(self):
ActionBase.__init__(self)
pass

def populate_model(self, db, citation, form_event, model):
# if there is no date on the form, no actions can be performed
if form_event.get_date_object():
parent = model.append(None, (_("Add Birth event"), None, None))
for item in db.find_backlink_handles(form_event.get_handle(),
include_classes=['Person']):
handle = item[1]
person = db.get_person_from_handle(handle)
for event_ref in person.get_event_ref_list():
if event_ref.ref == form_event.get_handle():
for attr in event_ref.get_attribute_list():
if (attr.get_type() == "Age"): # Form specific _attribute name
age_string = attr.get_value()
if age_string and represents_int(age_string):
age = int(age_string)
if age:
birth_date = form_event.get_date_object() - age
birth_date.make_vague()
# Age was rounded down to the nearest five years for those aged 15 or over
# In practice this rule was not always followed by enumerators
if age < 15:
# no adjustment required
birth_date.set_modifier(Date.MOD_ABOUT)
elif not birth_date.is_compound():
# in theory, birth_date will never be compound since 1841 census date was 1841-06-06. Let's handle it anyway.
# create a compound range spanning the possible birth years
birth_range = (birth_date - 5).get_dmy() + (False,) + birth_date.get_dmy() + (False,)
birth_date.set(Date.QUAL_NONE, Date.MOD_RANGE, birth_date.get_calendar(), birth_range, newyear=birth_date.get_new_year())
birth_date.set_quality(Date.QUAL_CALCULATED)

model.append(parent, (name_displayer.display(person), date_displayer.display(birth_date),
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)))

class OccupationEvent(ActionBase):
def __init__(self):
ActionBase.__init__(self)
Expand Down
10 changes: 10 additions & 0 deletions Form/actionbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ def AddEventToPerson(db, trans, person_handle, event_type, event_date_object, ev
person = db.get_person_from_handle(person_handle)
person.add_event_ref(event_ref)
db.commit_person(person, trans)

def represents_int(s):
"""
return True iff s is convertable to an int, False otherwise
"""
try:
int(s)
return True
except ValueError:
return False

0 comments on commit c1919d4

Please sign in to comment.