Exemplo n.º 1
0
def Salad(request):
    item_selections = request.POST
    if len(item_selections) !=1:
            Total_cost = 0.0

            if Order.objects.last() == None:
                od = Order(1)
            else:
                od = Order(Order.objects.last().id+1)

            od.save()
            for i in item_selections.getlist("salad"):
                obj = Menu.objects.all().filter(id=i)
                Total_cost += obj[0].Price_small
                od.Others.add(obj[0])
            od.order_total = Total_cost
            od.save()
            if Cart.objects.all().filter(user =str(request.user),order_status=False).last() == None:
                if Cart.objects.last() == None:
                    cart = Cart(1,user =str(request.user))

                else:
                    cart = Cart(Cart.objects.last().id + 1,user =str(request.user))

                cart.save()
            else:
                cart = Cart.objects.all().filter(user =str(request.user),order_status=False).first()

            cart.stuff.add(od)
            cart.Total += Total_cost
            cart.save()

            return JsonResponse({"output":"Nope"})
    else:
        return JsonResponse({"output":"Fail"})
Exemplo n.º 2
0
def add_to_cart(request):
    goodsid = request.GET.get('goodsid')
    carts = Cart.objects.filter(c_user=request.user).filter(c_goods_id=goodsid)
    if carts.exists():
        cart_obj = carts.first()
        cart_obj.c_goods_num = cart_obj.c_goods_num + 1
    else:
        cart_obj = Cart()
        cart_obj.c_goods_id = goodsid
        cart_obj.c_user = request.user
    cart_obj.save()
    data = {
        'status': 200,
        'msg': 'add success',
        'c_goods_num': cart_obj.c_goods_num
    }
    return JsonResponse(data)
Exemplo n.º 3
0
def Regular(request):
    item_selections =request.POST
    items = {}
    #print(item_selections)
    order = [None,None,None,None,None]
    for i in ["base","items","specials"]:
        if i in item_selections:
            if i == "base":
                order[0] = item_selections.getlist(i)[0]
            elif i == "items":
                for n in range(len(item_selections.getlist(i))):
                    order[1+n] = item_selections.getlist(i)[n]
            else:
                order[-1] = item_selections.getlist(i)[0]

    if "specials" in item_selections:
        if "specials_size" in item_selections:
            items['specials']= ["specials","specials_size",item_selections["specials"]]
        else:
            items['specials']=["specials",item_selections["specials"]]
    else:
        items['specials']=[]

    if "base" in item_selections:
        if "base_size" in item_selections:
            items['base']= ["base","base_size",item_selections["base"]]
        else:
            items['base']=["base",item_selections["base"]]
    else:
        items['base'] = []

    if "items" in item_selections:
        toppings = [int(i) for i in item_selections.getlist("items")]
        if "items_size" in item_selections:
            selection =[int(i) for i in item_selections.getlist("items_size")]
            items['toppings']= [toppings,selection]
        else:
            items['toppings']=[toppings]
    else:
        items['toppings']=[]

    if Order.objects.last() == None:
        od = Order(1,*order)
    else:
        od = Order(Order.objects.last().id+1,*order)


    if Cart.objects.all().filter(order_status=False,user=str(request.user)).last() == None:
        if Cart.objects.last() == None:
            cart = Cart(1,user = str(request.user))

        else:
            cart = Cart(Cart.objects.last().id + 1,user = str(request.user))

        cart.save()
    else:
        cart = Cart.objects.all().filter(order_status=False,user = str(request.user)).first()


    od.order_total = round(get_price(items,RegularPrice),2)
    od.save()
    cart.stuff.add(od)
    cart.Total += od.order_total
    cart.save()
    return HttpResponse("r-updated!")