Skip to content

Commit a12891c

Browse files
committed
Allow each action to indicate if the detail of the action can be edited by the user when run.
There are three editing options available to an action CANNOT_EDIT_DETAIL - no editing is possible CAN_EDIT_DETAIL - the user can choose to edit the detail MUST_EDIT_DETAIL - the user must edit the detail MUST_EDIT_DETAIL is intended to cater for cases where the action cannot be certain of some data. For example computing a date of birth from an age on a census form when the age is "1m"
1 parent d302904 commit a12891c

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

Form/UK1841.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def get_actions(dbstate, citation, form_event):
7373
db = dbstate.db
7474
actions = []
7575
for (person, attr) in actionutils.get_form_person_attr(db, form_event.get_handle(), 'Name'):
76-
actions.append((name_displayer.display(person), attr.get_value(),
76+
actions.append((name_displayer.display(person), attr.get_value(), actionutils.CANNOT_EDIT_DETAIL,
7777
lambda dbstate, uistate, track, citation_handle=citation.handle, person_handle=person.handle: PrimaryNameCitation.command(dbstate, uistate, track, citation_handle, person_handle)))
7878
return (_("Add Primary Name citation"), actions)
7979

@@ -96,7 +96,7 @@ def get_actions(dbstate, citation, form_event):
9696
alternate.set_first_name(attr.get_value())
9797
alternate.add_citation(citation.handle)
9898
detail = _('Given Name: {name}').format(name=attr.get_value())
99-
actions.append((name_displayer.display(person), detail,
99+
actions.append((name_displayer.display(person), detail, actionutils.MUST_EDIT_DETAIL,
100100
lambda dbstate, uistate, track, person_handle=person.handle, alternate_=alternate: AlternateName.command(dbstate, uistate, track, person_handle, alternate_)))
101101
return (_("Add alternate name"), actions)
102102

@@ -118,28 +118,32 @@ def get_actions(dbstate, citation, form_event):
118118
if form_event.get_date_object():
119119
for (person, attr) in actionutils.get_form_person_attr(db, form_event.get_handle(), 'Age'):
120120
age_string = attr.get_value()
121-
if age_string and actionutils.represents_int(age_string):
122-
age = int(age_string)
123-
if age:
124-
birth_date = form_event.get_date_object() - age
125-
birth_date.make_vague()
126-
# Age was rounded down to the nearest five years for those aged 15 or over
127-
# In practice this rule was not always followed by enumerators
128-
if age < 15:
129-
# no adjustment required
130-
birth_date.set_modifier(Date.MOD_ABOUT)
131-
elif not birth_date.is_compound():
132-
# in theory, birth_date will never be compound since 1841 census date was 1841-06-06. Let's handle it anyway.
133-
# create a compound range spanning the possible birth years
134-
birth_range = (birth_date - 5).get_dmy() + \
135-
(False,) + birth_date.get_dmy() + (False,)
136-
birth_date.set(Date.QUAL_NONE, Date.MOD_RANGE, birth_date.get_calendar(
137-
), birth_range, newyear=birth_date.get_new_year())
138-
birth_date.set_quality(Date.QUAL_CALCULATED)
139-
detail = _('Age: {age}\nDate: {date}').format(
140-
age=age_string, date=date_displayer.display(birth_date))
141-
actions.append((name_displayer.display(person), detail,
142-
lambda dbstate, uistate, track, citation_handle=citation.handle, person_handle=person.handle, birth_date_=birth_date: actionutils.add_event_to_person(dbstate, uistate, track, person_handle, EventType.BIRTH, birth_date_, None, citation_handle, EventRoleType.PRIMARY)))
121+
if age_string:
122+
birth_date = None
123+
if actionutils.represents_int(age_string):
124+
age = int(age_string)
125+
if age:
126+
birth_date = form_event.get_date_object() - age
127+
birth_date.make_vague()
128+
# Age was rounded down to the nearest five years for those aged 15 or over
129+
# In practice this rule was not always followed by enumerators
130+
if age < 15:
131+
# no adjustment required
132+
birth_date.set_modifier(Date.MOD_ABOUT)
133+
elif not birth_date.is_compound():
134+
# in theory, birth_date will never be compound since 1841 census date was 1841-06-06. Let's handle it anyway.
135+
# create a compound range spanning the possible birth years
136+
birth_range = (birth_date - 5).get_dmy() + \
137+
(False,) + birth_date.get_dmy() + (False,)
138+
birth_date.set(Date.QUAL_NONE, Date.MOD_RANGE, birth_date.get_calendar(
139+
), birth_range, newyear=birth_date.get_new_year())
140+
birth_date.set_quality(Date.QUAL_CALCULATED)
141+
detail = _('Age: {age}\nDate: {date}').format(
142+
age=age_string, date=date_displayer.display(birth_date))
143+
else:
144+
detail = _('Age: {age}').format(age=age_string)
145+
actions.append((name_displayer.display(person), detail, actionutils.CAN_EDIT_DETAIL if birth_date else actionutils.MUST_EDIT_DETAIL,
146+
lambda dbstate, uistate, track, citation_handle=citation.handle, person_handle=person.handle, birth_date_=birth_date: actionutils.add_event_to_person(dbstate, uistate, track, person_handle, EventType.BIRTH, birth_date_, None, citation_handle, EventRoleType.PRIMARY)))
143147
return (_("Add Birth event"), actions)
144148

145149

@@ -151,7 +155,7 @@ def get_actions(dbstate, citation, form_event):
151155
for (person, attr) in actionutils.get_form_person_attr(db, form_event.get_handle(), 'Occupation'):
152156
occupation = attr.get_value()
153157
if (occupation):
154-
actions.append((name_displayer.display(person), _('Description: {occupation}').format(occupation=occupation),
158+
actions.append((name_displayer.display(person), _('Description: {occupation}').format(occupation=occupation), actionutils.CAN_EDIT_DETAIL,
155159
lambda dbstate, uistate, track, citation_handle=citation.handle, person_handle=person.handle, occupation_=occupation: actionutils.add_event_to_person(dbstate, uistate, track, person_handle, EventType.OCCUPATION, form_event.get_date_object(), occupation_, citation_handle, EventRoleType.PRIMARY)))
156160
return (_("Add Occupation event"), actions)
157161

@@ -175,7 +179,7 @@ def get_actions(dbstate, citation, form_event):
175179
place = place_displayer.display(
176180
db, db.get_place_from_handle(form_event.get_place_handle()))
177181
detail = _('Place: {place}').format(place=place)
178-
actions.append((get_participant_from_event(db, form_event.get_handle()), detail,
182+
actions.append((get_participant_from_event(db, form_event.get_handle()), detail, actionutils.MUST_EDIT_DETAIL,
179183
lambda dbstate, uistate, track, citation_handle=citation.handle, people_handles=people: ResidenceEvent.command(dbstate, uistate, track, citation_handle, form_event.get_date_object(), form_event.get_place_handle(), people_handles)))
180184
return (_("Add Residence event"), actions)
181185

Form/actionutils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141

4242
_ = _trans.gettext
4343

44+
# Constants to define the options for editing the details of an action
45+
CANNOT_EDIT_DETAIL = 0
46+
CAN_EDIT_DETAIL = 1
47+
MUST_EDIT_DETAIL = 2
48+
49+
4450
def __init__():
4551
pass
4652

Form/formactions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
# Gramplet modules
5757
#
5858
# ------------------------------------------------------------------------
59+
import actionutils
5960
from editform import find_form_event
6061
from form import (get_form_id, get_form_type)
6162

@@ -92,7 +93,8 @@ class FormActions(object):
9293
RUN_INCONSISTENT_COL = 1
9394
ACTION_COL = 2
9495
DETAIL_COL = 3
95-
ACTION_COMMAND_COL = 4
96+
CAN_EDIT_DETAIL_COL = 4 # actionutils.CANNOT_EDIT_DETAIL, actionutils.CAN_EDIT_DETAIL or actionutils.MUST_EDIT_DETAIL
97+
ACTION_COMMAND_COL = 5
9698

9799
def __init__(self, dbstate, uistate, track, citation):
98100
self.dbstate = dbstate
@@ -151,7 +153,8 @@ def _create_dialog(self, title):
151153
box = Gtk.Box()
152154
top.vbox.pack_start(box, True, True, 5)
153155

154-
self.model = Gtk.TreeStore(bool, bool, str, str, GObject.TYPE_PYOBJECT)
156+
self.model = Gtk.TreeStore(
157+
bool, bool, str, str, int, GObject.TYPE_PYOBJECT)
155158
self.tree = Gtk.TreeView(model=self.model)
156159
renderer_text = Gtk.CellRendererText()
157160
column1 = Gtk.TreeViewColumn(_("Action"))
@@ -233,7 +236,7 @@ def _populate_model(self):
233236
if actions:
234237
# add the action category
235238
parent = self.model.append(
236-
None, (False, False, title, None, None))
239+
None, (False, False, title, None, actionutils.CANNOT_EDIT_DETAIL, None, False))
237240
for action_detail in actions:
238241
# add available actions within this category
239242
self.model.append(

0 commit comments

Comments
 (0)