I may be missing something, but I still don't see where sale_order_checkout touches the session (it has a form in the HTML, but it is not a web2py form with a _formkey token, so it doesn't use the session). I don't think your problem is the same as the one discussed in this thread.
Which of the two forms do you have to submit twice? More diagnostic info would be helpful (i.e., check developer tools in the browser and inspect request.vars, etc. on server when the form is submitted each time). Anthony On Monday, July 13, 2015 at 7:57:22 PM UTC-4, 黄祥 wrote: > > already tried to write the dummy session data in (sale_order and > sale_order_form) but still same (need submit twice), yet i got some bonus, > traceback error said : > > AttributeError: 'str' object has no attribute 'items' > > > *controllers/default.py* > def sale_order(): > session.sale_order = 'test' > return locals() > > def sale_order_form(): > session.sale_order = 'test' > form = SQLFORM.factory( > Field('product', 'reference product', > requires = IS_IN_DB(db((db.product. > quantity > 0) ), > db.product.id, db.product._format) ), > Field('quantity', 'integer', requires = IS_NOT_EMPTY() ), > ) > if form.process(formname = 'myform1').accepted: > response.flash = T('Form accepted') > > id = int(request.vars.product) > > row = db(db.product.id == id).select().first() > > quantity = int(request.vars.quantity) > price = int(row.selling_price) > session.sale_order[id] = quantity, price > > response.js = "jQuery('#sale_order_checkout').get(0).reload()" > elif form.errors: > response.flash = T('Form has errors') > return dict(form = form) > > *views/default/sale_order_checkout.load* > {{total_quantity = 0 }} > {{grand_total = 0 }} > > <table class = "table table-condensed table-hover"> > <tr> > <th>{{=T('Product') }}</th> > <th>{{=T('Price') }}</th> > <th>{{=T('Quantity') }}</th> > <th>{{=T('Total Price') }}</th> > <th>{{=T('Action') }}</td> > </tr> > {{for id, (quantity, price) in session_detail.items():}} > {{product = db.product(id) }} > {{total_price = quantity * price}} > {{total_quantity += quantity}} > {{grand_total += total_price}} > <tr> > <td> > {{=SPAN(product.name) }} > </td> > <td>{{=SPAN('Rp. %s' % format(price, ",d").replace(",", ".") ) > }}</td> > <td> > <form> > <input name = "{{='quantity_%s' % id}}" value = > "{{=quantity}}" > onkeyup = "ajax('{{=URL(link_callback, vars = dict(id = > id, price = price, > action = 'adjust_total') ) }}', ['{{='quantity_%s' % > id}}'], ':eval' )" /> > </form> > </td> > <td>Rp. {{=SPAN('%s' % format(total_price, ",d").replace(",", > "."), _id = 'total_price_%s' % id) }}</td> > <td> > {{=SPAN(A(I(_class = 'glyphicon glyphicon-remove-sign'), > callback = URL(link_callback, > vars = dict(id = id, action = 'remove') ), delete = > 'tr', > _title = 'Remove %s' % product.name) ) }} > </td> > </tr> > {{pass}} > <tr> > <td></td> > <td>{{=B(T('Grand Total') ) }}</td> > <td>{{=SPAN('%s' % format(total_quantity, ",d").replace(",", "."), > _id = 'total_quantity') }}</td> > <td>Rp. {{=SPAN('%s' % format(grand_total, ",d").replace(",", > "."), _id = 'grand_total') }}</td> > <td></td> > </tr> > </table> > > {{=SPAN(A(T('Empty'), _href = URL(link_empty), _title = 'Empty', > _onclick = "javascript:return confirm('Are you sure you want to > empty?')", > _class = 'btn btn-info') ) }} > > best regards, > stifan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.