Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion infogami/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,24 @@ def fill(self, size):
self.append(None)

def setdefault(self, index, value):
index = int(index)
"""Set a value at the given index, expanding the list as needed.

Non-numeric indices (e.g. template placeholders like
'[row_translated_names]') are silently ignored so that unprocessed
repetition-widget rows do not crash form submission.

>>> bl = betterlist()
>>> bl.setdefault('0', 'a')
'a'
>>> bl.setdefault('[row_translated_names]', 'x') is None
True
>>> bl # list is unchanged after non-numeric index
['a']
"""
try:
index = int(index)
except (ValueError, TypeError):
return None
self.fill(index + 1)
if self[index] is None:
self[index] = value
Expand Down