Skip to content

Commit

Permalink
Rename populate_model to get_actions. get_actions returns the possibl…
Browse files Browse the repository at this point in the history
…e actions.

This avoids leaking FormAction implementation detail (the use of a TreeStore) into the action classes.
  • Loading branch information
stevenyoungs committed Dec 30, 2019
1 parent a54ee03 commit 3dbc678
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
24 changes: 14 additions & 10 deletions Form/UK1841.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ def __init__(self):
ActionBase.__init__(self)
pass

def populate_model(self, dbstate, citation, form_event, model):
def get_actions(self, dbstate, citation, form_event):
db = dbstate.db
parent = model.append(None, (_("Add Primary Name citation"), None, None))
actions = []
for (person, attr) in ActionBase.get_form_person_attr(db, form_event.get_handle(), 'Name'):
model.append(parent, (name_displayer.display(person), attr.get_value(),
pass
actions.append((name_displayer.display(person), attr.get_value(),
lambda dbstate, uistate, track, citation_handle = citation.handle, person_handle = person.handle: PrimaryNameCitation.command(dbstate, uistate, track, citation_handle, person_handle)))
return (_("Add Primary Name citation"), actions)

def command(dbstate, uistate, track, citation_handle, person_handle):
db = dbstate.db
Expand All @@ -73,11 +75,11 @@ def __init__(self):
ActionBase.__init__(self)
pass

def populate_model(self, dbstate, citation, form_event, model):
def get_actions(self, dbstate, citation, form_event):
db = dbstate.db
actions = []
# 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 (person, attr) in ActionBase.get_form_person_attr(db, form_event.get_handle(), 'Age'):
age_string = attr.get_value()
if age_string and represents_int(age_string):
Expand All @@ -97,19 +99,21 @@ def populate_model(self, dbstate, citation, form_event, model):
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),
actions.append((name_displayer.display(person), date_displayer.display(birth_date),
lambda dbstate, uistate, track, citation_handle = citation.handle, person_handle = person.handle, birth_date_ = birth_date: ActionBase.add_event_to_person(dbstate, uistate, track, person_handle, EventType.BIRTH, birth_date_, None, citation_handle, EventRoleType.PRIMARY)))
return (_("Add Birth event"), actions)

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

def populate_model(self, dbstate, citation, form_event, model):
def get_actions(self, dbstate, citation, form_event):
db = dbstate.db
parent = model.append(None, (_('Add Occupation event'), None, None))
actions = []
for (person, attr) in ActionBase.get_form_person_attr(db, form_event.get_handle(), 'Occupation'):
occupation = attr.get_value()
if (occupation) :
model.append(parent, (name_displayer.display(person), occupation,
lambda dbstate, uistate, track, citation_handle = citation.handle, person_handle = person.handle, occupation_ = occupation: ActionBase.add_event_to_person(dbstate, uistate, track, person_handle, EventType.OCCUPATION, form_event.get_date_object(), occupation_, citation_handle, EventRoleType.PRIMARY)))
actions.append((name_displayer.display(person), occupation,
lambda dbstate, uistate, track, citation_handle = citation.handle, person_handle = person.handle, occupation_ = occupation: ActionBase.add_event_to_person(dbstate, uistate, track, person_handle, EventType.OCCUPATION, form_event.get_date_object(), occupation_, citation_handle, EventRoleType.PRIMARY)))
return (_("Add Occupation event"), actions)
6 changes: 5 additions & 1 deletion Form/formactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ def _populate_model(self):

for action_class in action_classes:
action = (action_class[1])()
action.populate_model(self.dbstate, self.citation, self.event, self.model)
(title, action_details) = action.get_actions(self.dbstate, self.citation, self.event)
if action_details:
parent = self.model.append(None, (title, None, None))
for action_detail in action_details:
self.model.append(parent, action_detail)

def run(self):
"""
Expand Down

0 comments on commit 3dbc678

Please sign in to comment.