|
From: Luke O. <lu...@me...> - 2003-04-10 00:34:49
|
Hey all -
We weren't able to figure out how to set the defaults for a
repeating field, from the existing code it would only take
a single common default.
Here's patched code to Field.py (around line 212, html()) to
allow optionally passing a list of default values for each
repeated field. Defaults for the field either can be
old-style single value, or a list that must have the same
number of elements as repetitions.
Enjoy,
- Luke
def html():
...
if options.get('repeat') and options['repeat'] > 1:
assert self._repeatable, "You must indicate a field is
repeatable when it is defined"
out = [html.input(type="hidden",
name=suffixMap(".repetitions",nameMap)(self.name()),
value=options['repeat'])]
if type(defaultValue) is not ListType:
# build list of defaults...
#this might be considered list-comp abuse.
defaultValues = \
[defaultValue for x in range(options['repeat']) ]
else:
assert len(defaultValue) == options['repeat']
defaultValues = defaultValue
for i in range(options['repeat']):
nm = suffixMap(".%i" % i, nameMap)
out.append(self.htWidget(defaultValue[i], options,
nameMap=nm))
return out
|