Skip to content

Commit

Permalink
Task History view: now doesn't crash when task is missing from a comp…
Browse files Browse the repository at this point in the history
…letion entry (#590)
  • Loading branch information
louking committed May 1, 2024
1 parent 59fed5b commit f94fa20
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion members/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# See https://packaging.python.org/guides/distributing-packages-using-setuptools/#semantic-versioning-preferred
__version__ = '1.6.3'
__version__ = '1.6.4.dev1'
__docversion__ = __version__
# uncomment for development
# __docversion__ = 'latest'
2 changes: 1 addition & 1 deletion members/views/admin/leadership_tasks_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def history_addlfields(tc, task):

history_formmapping['member'] = lambda tc: localuser2user(tc.user_id).name
history_formmapping['position'] = lambda tc: tc.position.position if tc.position else ""
history_formmapping['task'] = lambda tc: tc.task.task
history_formmapping['task'] = lambda tc: tc.task.task if tc.task else ""
history_formmapping['completion'] = lambda tc: dtrender.dt2asc(tc.completion)
history_formmapping['update_time'] = lambda tc: dttimerender.dt2asc(tc.update_time)
history_formmapping['updated_by'] = lambda tc: localuser2user(tc.updated_by).name
Expand Down
63 changes: 33 additions & 30 deletions members/views/admin/viewhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,39 +486,42 @@ def get_taskfields(tc, task):
:return: taskfields (list)
'''
taskfields = []
for ttf in task.fields:
f = ttf.taskfield
thistaskfield = {}
for key in TASKFIELD_KEYS.split(','):
thistaskfield[key] = getattr(f, key)
# displayvalue gets markdown translation
if key == 'displayvalue' and getattr(f, key):
thistaskfield[key] = markdown(getattr(f, key), extensions=['md_in_html', 'attr_list'])
thistaskfield['fieldoptions'] = get_fieldoptions(f)
if tc:
# field may exist now but maybe didn't before
field = InputFieldData.query.filter_by(field=f, taskcompletion=tc).one_or_none()

# field was found
if field:
value = field.value
if f.inputtype != INPUT_TYPE_UPLOAD:
thistaskfield['value'] = value

# check for task as this might be null https://github.com/louking/members/issues/590
if task:
for ttf in task.fields:
f = ttf.taskfield
thistaskfield = {}
for key in TASKFIELD_KEYS.split(','):
thistaskfield[key] = getattr(f, key)
# displayvalue gets markdown translation
if key == 'displayvalue' and getattr(f, key):
thistaskfield[key] = markdown(getattr(f, key), extensions=['md_in_html', 'attr_list'])
thistaskfield['fieldoptions'] = get_fieldoptions(f)
if tc:
# field may exist now but maybe didn't before
field = InputFieldData.query.filter_by(field=f, taskcompletion=tc).one_or_none()

# field was found
if field:
value = field.value
if f.inputtype != INPUT_TYPE_UPLOAD:
thistaskfield['value'] = value
else:
file = Files.query.filter_by(fileid=value).one()
thistaskfield['value'] = a(file.filename,
href=url_for('admin.file',
interest=g.interest,
fileid=value),
target='_blank').render()
thistaskfield['fileid'] = value

# field wasn't found
else:
file = Files.query.filter_by(fileid=value).one()
thistaskfield['value'] = a(file.filename,
href=url_for('admin.file',
interest=g.interest,
fileid=value),
target='_blank').render()
thistaskfield['fileid'] = value

# field wasn't found
thistaskfield['value'] = None
else:
thistaskfield['value'] = None
else:
thistaskfield['value'] = None
taskfields.append(thistaskfield)
taskfields.append(thistaskfield)

return taskfields

Expand Down

0 comments on commit f94fa20

Please sign in to comment.