Tuples are unmutable (you can't change them), so they don't have a replace
attribute. I you want to change your the values into your tuples use list
instead.

Richard

On Tue, Aug 28, 2012 at 3:44 AM, Bill Thayer <[email protected]> wrote:

> The example from the web2py application cookbook runs fine but when I
> tweak it I get
> <type 'exceptions.AttributeError'> 'tuple' object has no attribute
> 'replace'
> In the code below, mine is on top named test() for input a test request.
> The function named wizard came from the cookbook.
> def tests():
>     STEPS = {
>          0: ('db.test_order.charge_number', 'db.test_order.program',
> 'db.test_order.requestor','db.test_order.need_date',
> 'db.test_order.comments'), #collect order details first
>          1: ('db.test.part', 'db.test.sample', 'db.test.test_type',
> 'db.test.process'), # feilds for 1st page
>          2: ('db.test.cal_standard', 'db.test.start', 'db.test.stop',
> 'db.test.step'), # fileds for 2nd page
>          3: ('db.test.vds', 'db.test.ids'), # fields for 3rd page
>          4: URL('done')} # url when wizard completed
>
>     step = int(request.args(0) or 0)
>     if not step in STEPS: redirect(URL(args=0))
>
>
>     fields = STEPS[step]
>     print "Fields: " + str(fields) + " Step " + str(step)
>     if step==0:
>     session.wizard = {}
>     mytable = db.test_order
>     else:
>         mytable = db.test
>
>     if isinstance(fields, tuple):
>     form = SQLFORM.factory(*[f for f in mytable if f.name in fields])
>
>         if form.accepts(request, session):
>         session.wizard.update(form.vars)
>         redirect(URL(args=step+1))
>         else:
>         mytable.insert(**session.wizard)
>         session.flash = T('wizard completed')
>         redirect(fields)
>
>         return dict(form=form, step=step)
>
> def wizard():
>     STEPS = {0: ('field1', 'field2'), # fields for 1st page
>              1: ('field3', 'field4'), # fields for 2nd page
>              2: ('field5', 'field6'), # fields for 2nd page
>              3: URL('done')} # url when wizard completed
>     step = int(request.args(0) or 0)
>     if not step in STEPS: redirect(URL(args=0))
>     fields = STEPS[step]
>     print "Fields: " + str(fields) + " Step " + str(step)
>     if step==0:
>         session.wizard = {}
>     if isinstance(fields,tuple):
>         form = SQLFORM.factory(*[f for f in db.mytable if f.name in fields
> ])
>         if form.accepts(request,session):
>             session.wizard.update(form.vars)
>             redirect(URL(args=step+1))
>     else:
>         db.mytable.insert(**session.wizard)
>         session.flash = T('wizard completed')
>         redirect(fields)
>     return dict(form=form,step=step)
>
>
>
> def done():
>     return dict(message="End of wizard", back=A("New wizard", _href=URL(
> "wizard")))
>
>
>  --
>
>
>
>

-- 



Reply via email to