the previous is not work, it's work first because it still store the previous session, after clean session, cache and error it's not work. something strange in here. e.g. *controllers* session.sale_order_net = session.sale_order_net or {} #session.sale_order_net[0] = dict(discount = 0, delivery_fee = 0, packing_fee = 0, stamp_fee = 0, paid = 0) session.sale_order_net[0] = 0, 0, 0, 0, 0
*modules* if current.request.vars.action == 'adjust_total_net': discount = int(current.request.vars['discount'] ) delivery_fee = int(current.request.vars['delivery_fee'] ) packing_fee = int(current.request.vars['packing_fee'] ) stamp_fee = int(current.request.vars['stamp_fee'] ) paid = int(current.request.vars['paid'] ) #current.session.sale_order_net[0] = dict(discount = discount, delivery_fee = delivery_fee, packing_fee = packing_fee, stamp_fee = stamp_fee, paid = paid) # not work current.session.sale_order_net[0] = discount, delivery_fee, packing_fee, stamp_fee, paid # not work whether i store the session as dict() or list it still not update, i'm not using the variable to represent the session in the module (explicit it the session name and place [0] ), n it still not update, no error traceback occured, but the result is not expected (check with response.toolbar() the value is still 0 ) i know i missed something but can't figure it out, any idea how to face this using web2py way? thanks and best regards, stifan On Thursday, January 14, 2016 at 7:03:43 AM UTC+7, 黄祥 wrote: > > thank you so much for detail explaination, anthony. i found another way > around that work fine, don't know is this best practice or not because it > hard code to reserve the place in session variable. > like describe in the previous post, i want this module function can be > used by another functions in another controllers, so to explicit the > session is fine and then i must copy and rename the module function and > rename it's session name. > e.g. > *controllers/sale.py* > if 'sale_order' in request.function : > # session sale_order > session.sale_order = session.sale_order or {} > #session.sale_order_net = session.sale_order_net or dict(discount = 0, > delivery_fee = 0, packing_fee = 0, stamp_fee = 0, paid = 0) > #session.sale_order_net = session.sale_order_net or {'discount':0, > 'delivery_fee':0, 'packing_fee':0, 'stamp_fee':0, 'paid':0} > *session.sale_order_net = session.sale_order_net or {}* > * session.sale_order_net[0] = dict(discount = 0, delivery_fee = 0, > packing_fee = 0, stamp_fee = 0, paid = 0)* > #sale_order > session_sale_order = session.sale_order > session_sale_order_net = session.sale_order_net > > def sale_order_callback(): > return transaction.callback_0(session_sale_order, session_sale_order_net) > *modules/transaction.py* > def callback_0(session_order, session_order_net): > if current.request.vars.action == 'adjust_total_net': > discount = int(current.request.vars['discount'] ) > delivery_fee = int(current.request.vars['delivery_fee'] ) > packing_fee = int(current.request.vars['packing_fee'] ) > stamp_fee = int(current.request.vars['stamp_fee'] ) > paid = int(current.request.vars['paid'] ) > > *session_order_net[0] = dict(discount = discount, delivery_fee = > delivery_fee, packing_fee = packing_fee, stamp_fee = stamp_fee, paid = > paid)* > > thanks and best regards, > stifan > > On Thursday, January 14, 2016 at 1:58:07 AM UTC+7, Anthony wrote: >> >> Presumably you are calling this function as follows: >> >> callback_0(session.order, session.sale_order_net) >> >> The problem is you later have: >> >> session_order_net = dict(...) >> >> At that point, you are not modifying the session.sale_order_net object >> but simply assigning a new object to the local variable session_order_net. >> This is equivalent to doing: >> >> session_order_net = current.session.sale_order_net >> session_order_net = dict(...) >> >> In the above case, you wouldn't expect the second line to have any effect >> on session.sale_order_net -- the second line simply makes the first line >> irrelevant (i.e., it simply overwrites the value of the session_order_net >> variable that is local to the function). >> >> The earlier line: >> >> session_order[id] = ... >> >> works because in that case, you are not assigning a new object to the >> session_order variable but merely mutating the object to which >> session_order refers (i.e., session.order). >> >> If you want to completely replace the value of session.sale_order_net, >> then pass in the session object and do: >> >> session.sale_order_net = ... >> >> Anthony >> >> >> >> >> >> On Wednesday, January 13, 2016 at 12:48:11 AM UTC-5, 黄祥 wrote: >>> >>> is it possible to update 2 sessions values using web2py module? i've >>> tested it only first session value work, the second session value work if >>> explicit define in the module (but the module is used by another >>> controller, so i want to create just 1 module for all controllers). >>> e.g. >>> *modules/transaction.py* >>> def callback_0(session_order, session_order_net): >>> if current.request.vars.action == 'adjust_total': >>> id = int(current.request.vars.id) >>> quantity = int(current.request.vars['quantity_%s' % id]) >>> price = int(current.request.vars['price_%s' % id]) >>> *session_order[id] = quantity, price # the first parameter work* >>> total_price = quantity * price >>> total_quantity = 0 >>> grand_total = 0 >>> for calculation_id, (calculation_quantity, calculation_price) in >>> session_order.items(): >>> calculation_total_price = calculation_quantity * calculation_price >>> total_quantity += calculation_quantity >>> grand_total += calculation_total_price >>> return "jQuery('#total_price_%s').html('%s'); >>> jQuery('#total_quantity').html('%s'); jQuery('#grand_total').html('%s');" % >>> (id, >>> format(total_price, ",d").replace(",", "."), format(total_quantity, >>> ",d").replace(",", "."), >>> format(grand_total, ",d").replace(",", ".") ) >>> if current.request.vars.action == 'adjust_total_net': >>> discount = int(current.request.vars['discount'] ) >>> delivery_fee = int(current.request.vars['delivery_fee'] ) >>> packing_fee = int(current.request.vars['packing_fee'] ) >>> stamp_fee = int(current.request.vars['stamp_fee'] ) >>> paid = int(current.request.vars['paid'] ) >>> >>> * current.session.sale_order_net = dict(discount = discount, >>> delivery_fee = delivery_fee, packing_fee = packing_fee, stamp_fee = >>> stamp_fee, paid = paid) # this work when explicit tell the session name* >>> >>> * #session_order_net = dict(discount = discount, delivery_fee = >>> delivery_fee, packing_fee = packing_fee, stamp_fee = stamp_fee, paid = >>> paid)** # the second parameter not work, no error traceback occured but >>> the result is not expected (not updated value)* >>> >>> grand_total = sum(calculation_quantity * calculation_price for >>> calculation_id, (calculation_quantity, calculation_price) in >>> session_order.items() ) >>> grand_total_net = grand_total-discount+delivery_fee+packing_fee+stamp_fee >>> paid_return = paid-grand_total_net >>> >>> return "jQuery('#grand_total_net').html('%s'); >>> jQuery('#paid_return').html('%s');" % ( >>> format(grand_total_net, ",d").replace(",", "."), format(paid_return, >>> ",d").replace(",", ".") ) >>> >>> as in the example code above the bold code is work if i explicit it and >>> if i use the second parameter (*session_order_net*) that been passed by >>> function in controller, it is not work, the funny things is the first >>> parameter work (*session_order*). no error traceback occured but the >>> result is not expected. >>> >>> any idea how to get it work in web2py way? >>> >>> 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/d/optout.