hi,

is it possible to modify session value that store query as_list()?
e.g.
*controllers/**purchase_transaction.py*
def purchase_return_form():
fields = ['purchase_order_no', 'notes']
form = SQLFORM(db.purchase_return_header, fields = fields)
if form.validate():
session.purchase_return_header = dict(form.vars)
redirect(URL('purchase_return_checkout') )
return dict(form = form)

def purchase_return_checkout():
if not session.purchase_return_header:
redirect(URL('purchase_return_form') )
rows = db(db.purchase_order_detail.purchase_order_no == 
session.purchase_return_header['purchase_order_no']).select()
session.purchase_return_detail = rows.as_list()
return dict(session_purchase_return_header = 
session.purchase_return_header, 
session_purchase_return_detail = session.purchase_return_detail)

def purchase_return_callback():
id = int(request.vars.id)
qty = session.purchase_return_detail.get(id, 0)
if request.vars.action == 'subtract':
quantity = int(request.vars.quantity)
session.purchase_return_detail['quantity'] = quantity - 1
# test assign value # session.purchase_return_detail['quantity'] = 1
return str(session.purchase_return_detail['quantity'])
if request.vars.action == 'remove':
del session.purchase_return_detail[id]
redirect(URL('purchase_return_checkout') )

def purchase_return_empty():
session.purchase_return_header.clear()
session.purchase_return_detail.clear()
redirect(URL('purchase_return_form') )
return locals()

*views/purchase_transaction/purchase_return_checkout.html*
{{extend 'layout.html'}}

{{=H3(T('Purchase Return') ) }}

<table class = "table table-condensed table-hover">
    <tr>
        <th>{{=T('Product') }}</th>
        <th>{{=T('Quantity') }}</th>
        <th>{{=T('Action') }}</td>
    </tr>
{{for row in session_purchase_return_detail:}}
{{p = db.product(row['product']) }}
    <tr>
        <td>
{{=SPAN(p.name) }}
</td>
        <td>
{{=SPAN(row['quantity'], _id="item_%s" % row['id']) }}
</td>
        <td>
{{=SPAN(A(I(_class = 'icon-minus-sign'), _title='Substract Quantity', 
target='item_%s' % row['id'], 
callback=URL('purchase_return_callback', 
vars=dict(quantity=row['quantity'], action='subtract') ) ) ) }}
{{=SPAN(A(I(_class='icon-remove-sign'), 
callback=URL('purchase_return_callback', vars=dict(id=row['id'], 
action='remove') ), 
delete='tr', _title='Remove %s from purchase Return' % p.name) ) }}
</td>
    </tr>
{{pass}}
</table>

{{=SPAN(A(T('Process'), _href=URL('purchase_return'), _title='Process 
Purchase Return', 
  _onclick="javascript:return confirm('Are you sure you want to 
process?')", 
  _class='btn btn-success') ) }}
{{=SPAN(A(T('Empty'), _href=URL('purchase_return_empty'), _title='Empty 
Purchase Return', 
  _onclick="javascript:return confirm('Are you sure you want to empty?')", 
  _class='btn btn-success') ) }}

{{=response.toolbar() }}

the code above can show the session value that store query as_list() but, 
when i tried to modify it (substract, remove, empty) using ajax callback it 
not work.
1. error message during substract : An error occured, please reload the page
when i refresh the page, the session value is not change.
2. when i click to remove the value the table row is gone but when i 
refresh it, it show again (i assume the session is still remain)
3. when i click empty it return an traceback :

Traceback (most recent call last):
  File "/home/mdipierro/make_web2py/web2py/gluon/restricted.py", line 212, in 
restricted
  File 
"C:/Users/sugizo/Desktop/web2py/2.5.1/applications/onlineshopping/controllers/purchase_transaction.py"
 
<http://127.0.0.1:8000/admin/default/edit/onlineshopping/controllers/purchase_transaction.py>,
 line 192, in <module>
  File "/home/mdipierro/make_web2py/web2py/gluon/globals.py", line 194, in 
<lambda>
  File 
"C:/Users/sugizo/Desktop/web2py/2.5.1/applications/onlineshopping/controllers/purchase_transaction.py"
 
<http://127.0.0.1:8000/admin/default/edit/onlineshopping/controllers/purchase_transaction.py>,
 line 160, in purchase_return_empty
AttributeError: 'list' object has no attribute 'clear'


how to modify session value that store query as_list()?
another question is why session value that store query as_list() is not the 
real data? e.g.
purchase_return_detail:created_by:1Lcreated_on:2013-11-28 08:01:08
grand_total:2Lid:1Lis_active:Truemodified_by:1Lmodified_on:2013-11-28 
08:01:08price:1Lproduct:1Lpurchase_order_no:1Lquantity:2Ltotal_price:2L
purchase_return_header:notes:
purchase_order_no:1
as you can see the purchase_return_header session is human readable, while 
the purchase_return_detail session is not (1L, 2L).

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.

Reply via email to