What error occurs if you return locals()? If the view is expecting a
particular variable to be returned but that variable is not in locals(),
that would cause an error -- is that the issue?
Anthony
On Friday, February 15, 2013 7:39:17 PM UTC-5, 黄祥 wrote:
>
> thank you so much for your explaination, antony, i thought it was an
> illegal operation in web2py work flow or programming logic. but some times
> it's wise to decide it whether use redirect or return locals(), or is there
> any other options to do this except using redirect or return locals()?
>
> here is the example that can not use return locals(), because when the
> condition is true, it will return an error:
>
> def bill():
> if not session.order:
> session.flash=T("Order Now!!!")
> redirect(URL('product'))
> for k, v in session.order.items():
> if v==0:
> del session.order[k]
> * redirect(URL('order')) # if use return locals() an error
> will occur*
> import datetime
> import uuid
> invoice_no=str(datetime.date.today())+'-'+str(uuid.uuid4())
> grand_total=sum(db.product(id).unit_price*qty for id, qty in
> session.order.items())
> form=SQLFORM.factory(Field('note', 'text'))
> if form.accepts(request,session):
> for key, value in session.order.items():
> db.sale.insert(invoice_no=invoice_no,
> product_id=key,
> quantity=value,
> unit_price=db.product(key).unit_price,
> total_price=db.product(key).unit_price*value,
> grand_total=grand_total,
> note=form.vars.note)
> db(db.product.id==key).update(quantity=db.product.quantity -
> value)
> session.order.clear()
> session.flash=T("Thank you for your Order")
> redirect(URL('invoice', args=invoice_no))
> return dict(order=session.order, form=form, grand_total=grand_total)
>
--
---
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.