Hello all !
In order for one to successfully manipulate and/or modify some snippets of 
code, one needs to understand fully what these snippets of codes do in the 
context they are used and placed ! ( off course !!! )

There is something that escapes me ... or that I do not fully comprehend ! 
... and hopefully, one of you reading this post, will enlighten me !

First of all, let me explain what my objectives are, how I am approaching 
it :
I have 3 tables, and my objective is to present the future visitor with a 
form wizard in order to fill out these 3 tables by using SQLFORM.factory ! 
( with about 17 different fields in total )
putting it all on one page is simple ! but does not look good  ! I much 
prefer the form wizard approach
like the one on this link :
https://github.com/mdipierro/web2py-recipes-source/raw/master/apps/04_advanced_forms/web2py.app.form_wizard.w2p

I have learned that SQLFORM.factory can be used without the need to mention 
the related table name, it can work with only the fields needed in order to 
create the form  
so that way, multiple tables can be put on one single form page and after 
submission and validation, we insert the values of these fields in their 
appropriate tables and the trick is done ! it works well for one page form !

I have also learned that we can use the table_name attribute ! ( I will 
return on that later ) !

In the form wizard, there is that line of code within the form wizard 
example ( in the controller )

def wizard():
   STEPS = {0: ('field1','field2'), # fields for 1st page
      1: ('field3','field4'), # fields for 2nd page
      2: ('field5,''field6'), # fields for 3rd 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]
   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)
 

The lines of code that I have problems with fully understanding are 
underlined in red above ! can someone please explain it to me in plain 
english !! what does that line does,  with the star ( * ) in front of the 
[...the for loop...], ?
thank you !

Knowing that I have 3 tables, i cannot use that code as is ! because the 
real table name "db.mytable" is used !! I have 3 different tables !
the fields are fields of the 3 tables ... 

can I use the table_name attribute in this context ... ( like table_name = 
dummy_table ) while this attribute does not really exist in my db ... just 
for the session .. and later on ... when it is time to insert the fields 
into my real 3 tables, I  replace the following single line of code seen 
above  : 

db.mytable.insert(**session.wizard)

and replacing it with 3 lines of code like :

db.mytable1.insert(**db.dummy_table._filter_fields(form.vars) 
db.mytable2.insert(**db.dummy_table._filter_fields(form.vars) 
db.mytable3.insert(**db.dummy_table._filter_fields(form.vars) 


Can someone shed some light for me ... I have tried it ! .. and it does not 
work ! ... and I am thinking that it should ! ... am I wrong ??? ..

thank you for any assistance on this matter !

Don

**

-- 



Reply via email to