コード例 #1
0
def add_item(request, chip_id, rf_id):
    order = Order.objects.all().filter(chip__tag=chip_id).order_by('-created')
    if len(order) > 0:
        order = order[0]
        order.created = datetime.datetime.now()
        order.save()
        sku = SKU.objects.all().filter(rfid=rf_id)
        if len(sku) == 0:
            return HttpResponse('{-1}')
        sku = sku[0]
        item = Item.objects.all().filter(order=order, sku=sku)
        if len(item) > 0:
            item = item[0]
            item.quantity += 1
            item.save()
        else:
            item = Item(
                    sku=sku,
                    quantity=1,
                    order=order,
            )
            item.save()
        return HttpResponse('{' + str(sku.title) + ' Rs.' + str(sku.price) + '/-}')
    else:
        return HttpResponse('{-1}')
コード例 #2
0
def add_item(request, chip_id, rf_id):
    order = Order.objects.all().filter(chip__tag=chip_id).order_by('-created')
    if len(order) > 0:
        order = order[0]
        order.created = datetime.datetime.now()
        order.save()
        sku = SKU.objects.all().filter(rfid=rf_id)
        if len(sku) == 0:
            return HttpResponse('{-1}')
        sku = sku[0]
        item = Item.objects.all().filter(order=order, sku=sku)
        if len(item) > 0:
            item = item[0]
            item.quantity += 1
            item.save()
        else:
            item = Item(
                sku=sku,
                quantity=1,
                order=order,
            )
            item.save()
        return HttpResponse('{' + str(sku.title) + ' Rs.' + str(sku.price) +
                            '/-}')
    else:
        return HttpResponse('{-1}')
コード例 #3
0
def show_food_by_type(request, type):
    items = Item.get_items_by_type(type)
    types = Item.get_types()
    context = {
        'items': items,
        'types': types,
    }
    return render(request, 'order/show.html', context=context)
コード例 #4
0
def newFoodItem(request):
    if request.method == "POST":
        form = FoodInputForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            type = form.cleaned_data['type']
            stock = form.cleaned_data['stock']
            price = form.cleaned_data['price']

            newMenuItem = NewMenuItemContext(name, type,stock, price)
            Framework = InterceptorFramework()
            newfoodInterceptor = food_interceptor()
            Framework.register_food_interceptor(newfoodInterceptor)

            #passes context object to framework then dispatcher then interceptor
            Framework.on_log_event(newMenuItem)

            newfood = foodfactory.create_food(type,name,price,stock)
            newMenuItem = Item(name=newfood.getfoodname(),
                               type=newfood.getfoodtype(),
                               price=newfood.getfoodprice(),
                               stock=newfood.getfoodstock())
            newMenuItem.save()

    form = FoodInputForm()
    return render(request, 'main/food.html', {"form":form})
コード例 #5
0
def edit_item_amount_page(request):
    """ Edit food item """
    validate(instance=request.body, schema=item_schema)
    body = json.loads(request.body)
    responsemessage = Item.edit_item_amount(body['item_id'], body['count'])
    for entry in responsemessage:
        try:
            responsemessage[entry] = model_to_json(responsemessage[entry])
        except AttributeError:
            pass
    return JsonResponse(responsemessage)
コード例 #6
0
def follow(request: WSGIRequest):
    """
        request_body:
        {
            "order_id": 1,
            "creator": "Sam",
            "product": "雞排",
            "count": 1,
            "remarks": "胡椒、不要辣"
        }

        response_body:
        {
            "status": "success"
        }
    """
    if request.method == 'POST':
        data_in = json.loads(request.body)

        # check expired
        order = Order.objects.filter(id=data_in['order_id']).first()
        if order is None:
            return _json(status='Failed to follow order', exception='order id not found')
        if order.is_expired():
            return _json(status='Failed to follow order', exception='order expired')

        try:
            item = Item()
            item.order = order
            user = User.objects.filter(name=data_in['creator']).first()
            if user is None:
                user = User()
                user.name = data_in['creator']
            item.creator = user
            item.product = data_in['product']
            item.remarks = data_in['remarks']
            item.count = data_in['count']
            item.save()
        except Exception as e:
            return _json(status='Failed to follow order', exception=str(e), data_in=data_in)
        return _json(status='Create follow item', item_id=item.id, data_in=data_in)
    return _json(status='No such method')
コード例 #7
0
def show_food(request):
    default_type = Item.get_types().first()
    return redirect(reverse('show_food_by_type', kwargs={'type':
                                                         default_type}))
コード例 #8
0
def get_items_by_cart_page(request):
    """Get all items associated with a given cart"""
    items = Item.get_items_by_cart(request.GET['cart_id'])
    items = models_to_json(items)
    return JsonResponse({'items': items})
コード例 #9
0
def remove_item_page(request):
    """ Remove Item from database """
    validate(instance=request.body, schema=item_schema_remove)
    body = json.loads(request.body)
    Item.remove_item(body['item_id'])
    return HttpResponse('success')
コード例 #10
0
def insert_item_page(request):
    """ Insert item to database """
    validate(instance=request.body, schema=item_schema)
    body = json.loads(request.body)
    item = Item.new_item(body['cart_id'], body['food_id'], body['count'])
    return JsonResponse(model_to_json(item))