Hello Massimo,
I think I am onto something !
I have modified my model as follows :
defaultfoto = [ 'defaultuser.png','defaultplayer.png','defaultcoach.png']
defaultuserpics = { 0:IMG(_src=URL('static','images/'+ defaultfoto[0])),
1:IMG(_src=URL('static','images/'+ defaultfoto[1])),
2:IMG(_src=URL('static','images/'+ defaultfoto[2])),
3:DIV(_class='previewpic')}
I tweaked my code a bit ! and I am happy to say that I have made some
progress !
the controller now looks as follows :
def register():
import os
STEPS = {0: ('Iagreeto','first_name','last_name','email',
'email_check','password','sex','birth_date','usertype','user_adress',
'user_city','user_prov','user_postalcode','Country'),
1: ('the_user','user_speaks','more_Lang','user_image',
'user_picture','user_description','user_soccerstory'), # final step
2: URL('user',args='profile')}
step = int(request.args(0) or 0)
if not step in STEPS: redirect(URL(args=0))
fields = STEPS[step]
if step==0:
session.register = {}
if isinstance(fields,tuple):
mytables = ['auth_user','user_info']
form_fields = []
[form_fields.extend([db[t][f] for f in db[t].fields if f in fields
]) for t in mytables]
form = SQLFORM.factory(*form_fields)
if form.accepts(request,session):
session.register.update(form.vars)
db.auth_user.insert(**db.auth_user._filter_fields(session.
register))
db.user_info.insert(**db.user_info._filter_fields(session.
register))
redirect(URL(args=step+1))
else :
for n in xrange (0, 3):
if db.user_info.the_user_image == defaultuserpics[n]:
db.user_info.user_picture.default = lambda: open(os.path.
join(request.folder, 'static','images/'+ defaultfoto[n]), 'rb')
db.user_info.insert(**db.user_info._filter_fields(session.register
))
session.flash = T('Signup completed')
redirect(fields)
return dict(form=form,step=step)
I checked and the data makes it to both tables but even when the form is
not fully process !
I get an error at the end. in one of my test run it tells me
<class '_mysql_exceptions.IntegrityError'> (1062, "Duplicate entry
'[email protected]' for key 'email'")
How do I tweak the above code to avoid that duplicate entry attempt in the
tables ... i wonder where could this have happen ??? ... I only affected
the auth_user table once !!
could it be the "the_user" field which is a db.auth_user type ??? ...
thank you
Don
--