The current implementation of RepeatingFieldSet? creates a set of fieldsets with common attributes; for example, legends are the same for each fieldset. In addition, the variables in each fieldset are automatically numbered -- one might want to give them custom names.
Here is an implementation of the widget that accepts lists of the size of repetitions for legends and fields.
class RepeatingFieldSetPlus(RepeatingFormField):
"""
A widget similar to RepeatingFieldSet, but with differentiation
between each field set. Accepts ids and legends as lists.
"""
template="""
<div xmlns:py="http://purl.org/kid/ns#">
<fieldset py:for="repetition, id in enumerate(ids)"
class="${field_class}"
id="${field_id}_${id}"
>
<legend py:if="legends[repetition]"
py:content="legends[repetition]" />
<div py:for="field in hidden_fields"
py:replace="field.display(value_for(field[repetition]),
**params_for(field[repetition]))"
/>
<label class="fieldlabel" for="${field.field_id}"
py:content="field.label" />
<span py:replace="field.display(value_for(field),
**params_for(field))" />
<span py:if="error_for(field)" class="fielderror"
py:content="error_for(field)" />
<span py:if="field.help_text" class="fieldhelp"
py:content="field.help_text" />
</fieldset>
</div>
"""
params = ["legends", "ids", "table_attrs"]
params_doc = {'legend' : _('Text to display as the legend '
'for the fieldset')}
legends = None
ids = None
table_attrs = {}
Can be called like this:
RepeatingFieldSetPlus(
ids = [f.id for f in foo.items]
legends = [f.leg for f in foo.items]
fields=[SingleSelectField("foo_%s" % f.id) for f in foo.items]
I hope I'm even somewhat close to something useful/unimplemented here..