Skip to content

Commit 3dbc678

Browse files
committed
Rename populate_model to get_actions. get_actions returns the possible actions.
This avoids leaking FormAction implementation detail (the use of a TreeStore) into the action classes.
1 parent a54ee03 commit 3dbc678

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

Form/UK1841.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ def __init__(self):
5454
ActionBase.__init__(self)
5555
pass
5656

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

6466
def command(dbstate, uistate, track, citation_handle, person_handle):
6567
db = dbstate.db
@@ -73,11 +75,11 @@ def __init__(self):
7375
ActionBase.__init__(self)
7476
pass
7577

76-
def populate_model(self, dbstate, citation, form_event, model):
78+
def get_actions(self, dbstate, citation, form_event):
7779
db = dbstate.db
80+
actions = []
7881
# if there is no date on the form, no actions can be performed
7982
if form_event.get_date_object():
80-
parent = model.append(None, (_("Add Birth event"), None, None))
8183
for (person, attr) in ActionBase.get_form_person_attr(db, form_event.get_handle(), 'Age'):
8284
age_string = attr.get_value()
8385
if age_string and represents_int(age_string):
@@ -97,19 +99,21 @@ def populate_model(self, dbstate, citation, form_event, model):
9799
birth_date.set(Date.QUAL_NONE, Date.MOD_RANGE, birth_date.get_calendar(), birth_range, newyear=birth_date.get_new_year())
98100
birth_date.set_quality(Date.QUAL_CALCULATED)
99101

100-
model.append(parent, (name_displayer.display(person), date_displayer.display(birth_date),
102+
actions.append((name_displayer.display(person), date_displayer.display(birth_date),
101103
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)))
104+
return (_("Add Birth event"), actions)
102105

103106
class OccupationEvent(ActionBase):
104107
def __init__(self):
105108
ActionBase.__init__(self)
106109
pass
107110

108-
def populate_model(self, dbstate, citation, form_event, model):
111+
def get_actions(self, dbstate, citation, form_event):
109112
db = dbstate.db
110-
parent = model.append(None, (_('Add Occupation event'), None, None))
113+
actions = []
111114
for (person, attr) in ActionBase.get_form_person_attr(db, form_event.get_handle(), 'Occupation'):
112115
occupation = attr.get_value()
113116
if (occupation) :
114-
model.append(parent, (name_displayer.display(person), occupation,
115-
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)))
117+
actions.append((name_displayer.display(person), occupation,
118+
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)))
119+
return (_("Add Occupation event"), actions)

Form/formactions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ def _populate_model(self):
149149

150150
for action_class in action_classes:
151151
action = (action_class[1])()
152-
action.populate_model(self.dbstate, self.citation, self.event, self.model)
152+
(title, action_details) = action.get_actions(self.dbstate, self.citation, self.event)
153+
if action_details:
154+
parent = self.model.append(None, (title, None, None))
155+
for action_detail in action_details:
156+
self.model.append(parent, action_detail)
153157

154158
def run(self):
155159
"""

0 commit comments

Comments
 (0)