'N'+''.join('o' for in in range(100))+'!'
yes there is a better way :-)
def bunch_update_with_multi_form():
for k in range(31): locals()['form%s' % k] = None # not sure if
necessary
if not request.args(0) in [... list of allowed tables...]:
redirect(URL('error'))
tablename, table = request.args(0), db[request.args(0)]
response.flash = ''
formset = dict()
for k,item in enumerate(rows):
form _name= 'form%s' % k
form = formset[form_name] = SQLFORM(table)
for fieldname in table.fields:
if fieldname in item[tablename]:
form.vars[fieldname] = item[tablename][fieldname]
if form.process().accepted:
response.flash += '...'
elif form.errors:
response.flash += 'form %s has errors ' % form_name
return formset
On Dec 12, 12:43 pm, Richard <[email protected]> wrote:
> Hello,
>
> Is there a better way of doing this :
>
> def bunch_update_with_multi_form():
> form0=None
> form1=None
> form3=None
> form4=None
> form5=None
> form6=None
> form7=None
> form8=None
> form9=None
> form10=None
> form11=None
> form12=None
> form13=None
> form14=None
> form15=None
> form16=None
> form17=None
> form18=None
> form19=None
> form20=None
> form21=None
> form22=None
> form23=None
> form24=None
> form25=None
> form26=None
> form27=None
> form28=None
> form29=None
> form30=None
>
> form_num = 0
> for i in rows:
> globals()['form%s'%form_num] = SQLFORM(db[request.args(0)])
> for f in db[request.args(0)].fields:
> if globals()['form%s'%form_num] != None:
> globals()['form%s'%form_num].vars[f] =
> i[request.args(0)][f]
> if globals()['form%s'%form_num] != None:
> if globals()['form%s'%form_num].process().accepted:
> response.flash = '...'
> elif globals()['form%s'%form_num].errors:
> response.flash = 'form has errors'
> form_num+=1
> return
> dict(table=table,form0=form0,form1=form1,form2=form2,form3=form3,form4=form
> 4,form5=form5,form6=form6,form7=form7,form8=form8,form9=form9,form10=form10
> ,form11=form11,form12=form12,form13=form13,form14=form14)
>
> When using web2py shell I don't have any problem to execute my loops,
> but in app I am getting only one correct form on 14...
>
> I read in the book that SQLFORM is creating it on unique form
> identifier but there is no example about that... Should I user SQLFORM
> in view (put my loop there) to make it works :
>
> Thanks
>
> Richard