[Zope-CMF] Question.... or records attribute.

Jeffrey P Shell jeffrey@cuemedia.com
Mon, 8 Oct 2001 16:35:48 -0600


On Monday, October 8, 2001, at 04:29  PM, Ian Ford wrote:

> I have a form that send a form field call amount to a python script to
> create the catalog entry,
> the form field is being created dynamiclly so a user could enter more
> then one amount.
> (i.e. if a user selects to have two products that they need to order
> then the amount field will display twice.)
>
> I am trying to use the records attribute but it seems to be choking the
> python script.
> the format that I am send to the python script is
> name='items.amount:records' value='value typed'
>
> On the python script the parameter I am looking for is items.
> Then the context is as follows
>
> context.edit(amount=items.amount)
>

There is an important distinguishing characteristic between the 
type 'records' and 'record'.  'records' makes a list of record 
objects, 'record' makes a single one.

Change your python script to do:

for item in items:
	context.edit(amount=item.amount)

or change the HTML form to have:
name='item.amount:record' value='value typed'

If your form only has one 'item', you can just use the singular 
version.  If your form has multiple ones, use the plural, and then 
use the 'for...' loop in your python script.

Note that even if you only have one record when using the 'records' 
type, it still gets turned into a sequence.

--
jeffrey@cuemedia.com