how can i get and set the session value that is store as a tuple? e.g. *controllers/transaction.py* def purchase_order_callback(): #from gluon.debug import dbg #dbg.set_trace() id = int(request.vars.id) quantity, price = session.purchase_order.get(id, (0, 0) ) if request.vars.action == 'add': quantity = max(0, int(quantity) + 1) price = max(0, int(price) + 2) session.purchase_order[id] = quantity, price return str(session.purchase_order[id][0]) if request.vars.action == 'subtract': quantity = max(0, int(quantity) - 1) price = max(0, int(price) - 2) session.purchase_order[id] = quantity, price return str(session.purchase_order[id][0]) if request.vars.action == 'adjust_total_price': quantity = int(request.vars['quantity_%s' % id]) price = int(request.vars['price_%s' % id]) session.purchase_order[id] = quantity, price total_price = quantity * price grand_total = 0 for calculation_id, (calculation_quantity, calculation_price) in session.purchase_order.items(): calculation_total_price = calculation_quantity * calculation_price grand_total += calculation_total_price return "jQuery('#total_price_%s').html(%s);jQuery('#grand_total').html(%s);" % (str(id), str(total_price), str(grand_total))
*views/transaction/purchase_order.html* {{grand_total = 0 }} <table class="table table-condensed table-hover"> <tr> <th>{{=T('Name') }}</th> <th>{{=T('Quantity') }}</th> <th>{{=T('Price') }}</th> <th>{{=T('Total Price') }}</th> <th>{{=T('Action') }}</td> </tr> {{for id, (quantity, price) in session.purchase_order.items():}} {{product = db.product(id) }} {{total_price = quantity * price}} {{grand_total += total_price}} <tr> <td> {{=SPAN(product.name) }} </td> <td> <form> <input name="{{='quantity_%s' % product.id}}" value="{{=quantity}}" class="span1" onkeyup="ajax('{{=URL('purchase_order_callback', vars = dict(id = product.id, action = 'adjust_total_price') ) }}', ['{{='quantity_%s' % product.id}}'], ':eval' )" /> </form> </td> <td> <form> <input name="{{='price_%s' % product.id}}" value="{{=price}}" class="span1" onkeyup="ajax('{{=URL('purchase_order_callback', vars = dict(id = product.id, action = 'adjust_total_price') ) }}', ['{{='price_%s' % product.id}}'], ':eval' )" /> </form> </td> <td> Rp. {{=SPAN('%s' % format(total_price, ",d"), _id = 'total_price_%s' % product.id) }} </td> <td> {{=SPAN(A(I(_class='icon-remove-sign'), callback=URL('purchase_order_callback', vars=dict(id=product.id, action='remove') ), delete='tr', _title='Remove from Order') ) }} </td> </tr> {{pass}} <tr> <td colspan=2></td> <td>{{=B(T('Grand Total') ) }}</td> <td>Rp. {{=SPAN('%s' % format(grand_total, ",d"), _id = 'grand_total') }}</td> <td></td> </tr> </table> {{=SPAN(A(T('Process'), _href=URL('purchase'), _title='Process Purchase Order', _onclick="javascript:return confirm('Are you sure you want to process?')", _class='btn btn-success') ) }} {{=SPAN(A(T('Empty'), _href=URL('purchase_order_empty'), _title='Empty Purchase Order', _onclick="javascript:return confirm('Are you sure you want to empty?')", _class='btn btn-success') ) }} {{=response.toolbar()}} *session.purchase_order[id] = quantity, price* is work fine when add and subtract is execute but when adjust_total_price it's not work. trying to the debugging, at first the price and quantity type is int with the value, but when it reach the adjust_total_price, it return an error : TypeError: int() argument must be a string or a number, not 'NoneType' any idea how to resolve this? thanks and 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/groups/opt_out.