Ejemplo n.º 1
0
def buy_now(request,commoditie_id):
    if False == request.session.get('user_id',False):
        return render_to_response('buy_now.html',{'commoditie_id':commoditie_id},
            context_instance=RequestContext(request))
    username = Customers.objects.get(id=request.session['user_id']).CustomerName
    customer_instance = Customers.objects.get(id=request.session['user_id'])
    order_instance = Orders(Customer=customer_instance,CommoditieList=commoditie_id,
                                        OrderTime=datetime.now())
    order_instance.save()
    #assert False,order_instance
    return HttpResponseRedirect('/my_orders/')
Ejemplo n.º 2
0
def generate_order(request):
    if False == request.session.get('user_id',False):
        return render_to_response('login.html',{},
            context_instance=RequestContext(request))
    try:
        commoditie_list = ''
        ret = ShoppingCarts.objects.filter(Customer_id=request.session['user_id'])
        for item in ret:
            if commoditie_list == '':
                commoditie_list = str(item.Commoditie_id)
            else:
                commoditie_list += '@'
                commoditie_list += str(item.Commoditie_id)
        customer_instance = Customers.objects.get(id=request.session['user_id'])
        order_instance = Orders(Customer=customer_instance,CommoditieList=commoditie_list,
                                OrderTime=datetime.now())
        order_instance.save()
    except:
        return render_to_response('my_orders.html',{'total_price':str(sys.exc_info()[0]) + str(sys.exc_info()[1])},
                context_instance=RequestContext(request))
    #clear the chart for user_id after genarate the order
    ShoppingCarts.objects.filter(Customer_id=request.session['user_id']).delete()
    #assert False,commoditie_list
    return my_orders(request)