You have an old verison of sqlhtml but you discovered a bug and the bug persists in newer version. Can you try replace
record_id = dict([(k,request_vars[k]) for k in self.table._primarykey]) with record_id = dict([(k,request_vars.get(k,None)) for k in self.table._primarykey]) Let us know if this fixes it and I will put it in trunk. On Mar 11, 3:12 pm, MarKco <[email protected]> wrote: > Hi to everyone, > I know this issue probably is not so fresh and new, but please take a > look anyway. I searched for the solution a lot in the newsgroup, the > wiki, the book and some tutorials but couldn't find the place where I > went wrong. > > The situation is the following: > I have a web page interacting with a single DB table. The table, by > now, is stored in Web2py's SQLlite DB. > This is table definition: > > db.define_table('CUS_R5KHMAIL001', Field('evt_code', 'string', > length=20), > Field('mail_status', 'string', > length=4), > Field('codpdf', 'string', > length=50), > Field('sender', 'string', > length=30), > Field('object', 'string', > length=50), > Field('text', 'string', > length=2000), > Field('mail_errmess', 'string', > length=80), > Field('date_ins', 'datetime'), > Field('date_elab', 'datetime'), > Field('receivers', 'string', > length=1000), > primarykey=['evt_code'], > migrate=False > ) > > db.CUS_R5KHMAIL001.evt_code.requires = [IS_NOT_EMPTY(), > IS_NOT_IN_DB(db, db.CUS_R5KHMAIL001.evt_code)] > > Thisa seems to work, because when I invoke the controller with the > list_emails page I obtain the two records I put in the table. > > This is the code for the controller: > > # coding: utf8 > > def list_emails(): > _list = db().select(db.CUS_R5KHMAIL001.evt_code, > db.CUS_R5KHMAIL001.mail_status, > db.CUS_R5KHMAIL001.object) > th = THEAD(TH("Code"), TH("Status"), TH("Subject"), TH('Action'), > _class='cus') > return dict(list_rcds=_list, table_header=th) > > def detail(): > if len(request.args): > > records=db(db.CUS_R5KHMAIL001.evt_code==request.args[0]).select() > print records > if len(request.args) and len(records): > f = SQLFORM(db.CUS_R5KHMAIL001, records[0], > readonly=False) > if f.accepts(request.vars, session): > response.flash='form accepted' > elif f.errors: > response.flash='form has errors' > > return dict(form=f) > > So there are two pages: the first is the list_emails one, which simply > shows the records in the table. The second one is "detail", which > opens when a link is clicked. This is the page where I get the error: > when web2py interprets the if f.accepts(request.vars, session) > statement it throws a "KeyError: 'evt_code'" exception. I can't > understand why. > I saw that by replacing the if f.accepts(request.vars, session) with > if f.accepts(records[0], session) I could obtain a page with the form > filled with the right record. The only problem is that clearly in this > case the interpreter does not know how to handle data after some > change, so if I write something and click on "submit" all fields turn > back to their initial value. I tried to print out the value of > request.vars just before the if and I discovered that the variable is > full (I mean, request.vars.evt_code returns record's key), so what > could be the reason for such a strange behaviourr? I probably fortog > something, but what? > > I don't know if it can be useful, but this is the code for the view: > > list_emails.html: > {{extend 'layout.html'}} > <h1>EAM Mail Records</h1> > <table> > {{=table_header}} > {{for row in list_rcds:}} > <tr, id='cus'><td>{{=row.evt_code}}</td> > <td>{{=row.mail_status}}</td> > <td>{{=row.object}}</td> > <td>{{=A(T('Edit'), _href=URL(r=request, f="detail", > args=[row.evt_code]))}}</td> > </tr> > {{pass}} > </table> > > detail.html: > {{extend 'layout.html'}} > <h1>Record Detail</h1> > {{=form}} > > Concluding, this is the complete error trace: > > Traceback (most recent call last): > File "C:\web2py\gluon\restricted.py", line 173, in restricted > exec ccode in environment > File "C:/web2py/applications/test_mail/controllers/eammail.py", line > 45, in <module> > File "C:\web2py\gluon\globals.py", line 96, in <lambda> > self._caller = lambda f: f() > File "C:/web2py/applications/test_mail/controllers/eammail.py", line > 19, in detail > if f.accepts(request.vars, session): > File "C:\web2py\gluon\sqlhtml.py", line 715, in accepts > record_id = dict([(k,request_vars[k]) for k in > self.table._primarykey]) > KeyError: 'evt_code' > > Thanks in advance for your support > > -- > MarKco -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.

