#43: FormFieldRepeater repetitions=0 (possible fix)
----------------------+-----------------------------------------------------
Reporter: percious | Owner: alberto
Type: defect | Status: new
Priority: major | Milestone:
Component: core | Version: 0.9
Keywords: |
----------------------+-----------------------------------------------------
I'm using FormFieldRepeaterS to display FieldSetS 0 or more times.
This works fine if I populate my form with a list containing at least
one element, however, if I pass it a list with zero elements I get the
following error:
File '/home/mlp/.virtualenvs/order_cancellation_ng/lib/python2.5/site-
packages/ToscaWidgets-0.9.5dev_20090407-py2.5.egg/tw/core/base.py',
line 1046 in update_params
max(d['repetitions'], len(d['value']) + d.extra))
TypeError: object of type 'NoneType' has no len()
One 'workaround' was to set the repetitions parameter sent to the
FormFieldRepeater to '1', however this was not ideal as it resulted in
an unpopulated FieldSet if the list contained zero elements.
Another workaround is to override the FormFieldRepeater class'
update_params() implementation:
{{{
class ZeroRepetitionFieldRepeater(FormFieldRepeater):
"""
Hack to ensure FormFieldRepeater won't crash when repetitions are
set to
0.
"""
def update_params(self, param_dict):
if param_dict['value'] == None:
param_dict['value'] = []
super(ZeroRepetitionFieldRepeater, self).update_params(param_dict)
}}}
I suspect that the inability to set repetitions to zero is a bug, but
maybe I'm missing something here. Has anyone else had problems setting
repetitions to 0? Is this perhaps related to the specific version of
ToscaWidgets I'm using (0.9.3dev_20090407) ?
--
Ticket URL: <http://toscawidgets.org/trac/tw/ticket/43>
ToscaWidgets </trac/tw>
ToscaWidgets - Web Widgets