Exemple #1
0
def show(request):
    gifts = []
    order_items = request.session.get('order', {})
    if not order_items:
        return render_to_response('cart/show.html', {'gifts':gifts})
    total_price = 0
    for k, val in order_items.iteritems():
        gift = Gift.get_by_id(k)
        if gift:
            gift.count = val
            gifts.append(gift)
            total_price += gift.price * val
    form = OrderForm()
    if request.method == 'POST' and form.validate(request.form):
        order = form.save(commit=False)
        order.email = request.form.get('email', None)
        order.address = request.form.get('address', None)
        order.put()
        for k, v in request.session.get('order', {}).items():
            gift = Gift.get_by_id(k)
            if gift:
                oi = OrderItem(gift_id=gift, count=v)
                oi.in_order = order
                oi.put()
        clear_cart(request)
        return render_to_response('cart/confirm_complete.html')
    return render_to_response('cart/show.html', {'gifts':gifts,
                                                 'total_price':total_price,
                                                 'form':form.as_widget()})
Exemple #2
0
def confirm(request):
    if not request.session.get('order', {}):
        return redirect('/cart/show/')
    form = OrderForm()
    if request.method == 'POST' and form.validate(request.form):
        order = form.save()
        for k, v in request.session.get('order', {}).items():
            gift = Gift.get_by_id(k)
            if gift:
                oi = OrderItem(gift_id=gift, count=v)
                oi.in_order = order
                oi.put()
        clear_cart(request)
        return render_to_response('cart/confirm_complete.html')
    return render_to_response('cart/confirm.html', {'form':form.as_widget()})
Exemple #3
0
def simple_buy(request, id, count):
    gift = Gift.get_by_id(id)
    if not gift:
        return render_to_response('empty.html')
    form = OrderForm()
    if request.method == 'POST' and form.validate(request.form) and count:
        order = form.save()
        oi = OrderItem(gift_id=gift, count=count)
        oi.in_order = order
        oi.put()
        def txn():
                taskqueue.add(url=url_for('cart/send_order_to_manager',
                                    order_key=str(order.key())),
                                    transactional=True)
        db.run_in_transaction(txn)
        return render_to_response('cart/confirm_complete_text.html')
    return render_to_response('cart/cart_block.html', {'gift':gift, 'form':form.as_widget()})