Well, for starters, your link passes the value "empty" in the action
variable, but your order_callback() function tests for the value "reset" --
there is no condition for "empty".
On Wednesday, February 20, 2013 10:43:24 AM UTC-5, 黄祥 wrote:
>
> a, thank you so much for your detail info, anthony. i've tried it but
> still not work (no error occured), but what i'm expected to clear the
> session data is not achieve. i'm not sure why this is happened.
>
> *#controller : default.py*
> def order_callback():
> id=int(request.vars.id)
> if request.vars.action=='add':
> session.order[id]=session.order.get(id, 0)+1
> if request.vars.action=='subtract':
> session.order[id]=max(0,session.order.get(id, 0)-1)
> if request.vars.action=='remove':
> del session.order[id]
> redirect(URL('order'))
> if request.vars.action=='reset':
> session.order.clear()
> redirect(URL('product'), client_side=True)
> return str(session.order[id])
>
> *#view : order.html*
> <table width="100%">
> {{for id, qty in order.items():}}
> {{p=db.product(id)}}
> <tr>
> <td>{{=SPAN(p.product_name)}}</td>
> <td>{{=SPAN('Rp. %s' % p.unit_price)}}</td>
> <td>{{=SPAN(qty, _id='item_%s' % p.id)}}</td>
> <td>{{=SPAN(A('Add', callback=URL('order_callback', vars=dict(id=
> p.id, action='add')), target='item_%s' % p.id, _title='Add Quantity',
> _class='btn btn-navbar'))}} {{=SPAN(A('Subtract',
> callback=URL('order_callback', vars=dict(id=p.id, action='subtract')),
> target='item_%s' % p.id, _title='Substract Quantity', _class='btn
> btn-navbar'))}} {{=SPAN(A('Remove', callback=URL('order_callback',
> vars=dict(id=p.id, action='remove')), delete='tr', _title='Remove %s from
> Order' % p.product_name, _class='btn btn-navbar'))}} </td>
> </tr>
> {{pass}}
> </table>
>
> {{=SPAN(A('Empty', callback=URL('order_callback', vars=dict(id=p.id,
> action='empty')), target='item_%s' % p.id, _title='Empty Order',
> _class='btn btn-navbar'))}}
>
--
---
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.