Any ideas anyone?

My view look like this:
{{extend 'layout.html'}}
<h2>Balance: <span id="balance">{{=session.balance}}</span></h2>
{{for reward in rewards:}}
<img align="left"
src="{{#=URL(r=request,f='download',args=reward.image)}}"/>
<h2>{{=A(reward.title_fi,_href=URL(r=request,c='troop',f='reward',args=reward.id))}}
</h2>
{{include 'cart_item.html'}}
{{pass}}

cart_item.html looks like:
  Quantity in cart: <span
id="p{{=reward.id}}">{{=session.cart.get(reward.id,0)}}</span>
  <button
onclick="ajax('{{=URL(r=request,f='update_qty',vars=dict(id=reward.id,qty=1))}}',
[],':eval')",>+1</button>
  <button
onclick="ajax('{{=URL(r=request,f='update_qty',vars=dict(id=reward.id,qty=-1))}}',
[],':eval')",>-1</button>

and update_qty from the controller looks like:
def update_qty():
    reward_id = int(request.vars.id)
    old_qty = session.cart.get(reward_id,0)
    new_qty = max(0,min(old_qty+int(request.vars.qty),10))
    session.cart[reward_id] = new_qty
    if not session.cart[reward_id]: del session.cart[reward_id]
    session.balance += (new_qty-
old_qty)*db.reward[reward_id].criteria_sales_min
    return "jQuery('#p
%s').html(%s);jQuery('#balance').hide().html(%s).fadeIn()" \
        % (reward_id,new_qty,session.balance)

in a model file I have:
if not session.cart: session.cart = {} # {reward_id: quantity}
if not session.balance: session.balance = 0

I think that the update_qty part is executed as session.balance and
session.cart[reward.id] is updated but what happens then. Somehow the
balance and quantity should be updated on page and I think the problem
is there. But how is those updated?


Kenneth


On Jul 26, 11:26 am, Kenneth Lundström <kenneth.t.lundst...@gmail.com>
wrote:
>   Waauu, many thanks Massimo, that was exactly what I was looking for. I
> installed it and it works nicely but after modifying to fit my database
> model I can t the +1 and -1 buttons to work. Or they work but quantity
> and balance is not updated. If I reload the page numbers are updated and
> show correct figures.
>
> I m getting document.getElementById(t) is null in Firefox Error Console.
> It is the row
>
> jQuery.ajax({type: "POST", url: u, data: query, success: function(msg) { 
> document.getElementById(t).innerHTML=msg; } });
>
> that gives this error.
>
> Any ideas where to start looking for the problem?
>
> Kenneth

Reply via email to