Ejemplo n.º 1
0
def update_items(request):
    user, item_name, doc = read_request_item(request)
    print "UP", type(doc)
    item = is_owner(item= item_name , user= user)
    if item:
        update_item(item= item, key_value=doc)
        message = messages['ITEM_UPDATED_MESSAGE']
    else:
        message = messages['UNAUTHORISED_ACTION_MESSAGE']
    return message
Ejemplo n.º 2
0
def update_items(request):
    user, item_name, doc = read_request_item(request)
    print "UP", type(doc)
    item = is_owner(item=item_name, user=user)
    if item:
        update_item(item=item, key_value=doc)
        message = messages['ITEM_UPDATED_MESSAGE']
    else:
        message = messages['UNAUTHORISED_ACTION_MESSAGE']
    return message
Ejemplo n.º 3
0
def sell_items(request, item):
    s = Bids.search()
    s.aggs.bucket('SP', 'terms', field=ITEM_INDEX).metric('max_bid', 'max', field='bid_amount')
    response = s.execute()

    for term in response.aggregations.SP.buckets:
        if term.key == item.item_name:
            selling_price = term.max_bid.value

    buyer = get_bid(item_name=item.item_name, amount=selling_price)[0].bidder
    doc = dict(status="Sold", sold_to=buyer)
    update_item(item= item, key_value=doc)

    return HttpResponse("Item Sold: {0} at {1} to {2}".format(item.item_name, selling_price, buyer))
Ejemplo n.º 4
0
def sell_items(request, item):
    s = Bids.search()
    s.aggs.bucket('SP', 'terms', field=ITEM_INDEX).metric('max_bid',
                                                          'max',
                                                          field='bid_amount')
    response = s.execute()

    for term in response.aggregations.SP.buckets:
        if term.key == item.item_name:
            selling_price = term.max_bid.value

    buyer = get_bid(item_name=item.item_name, amount=selling_price)[0].bidder
    doc = dict(status="Sold", sold_to=buyer)
    update_item(item=item, key_value=doc)

    return HttpResponse("Item Sold: {0} at {1} to {2}".format(
        item.item_name, selling_price, buyer))