Ejemplo n.º 1
0
def view_bids(request):
    bidder, item_name = read_request_item(request)
    bid_dict= {}
    bid_list = get_bid(bidder=bidder)
    for bid in bid_list:
        print type(bid)
        bid_dict[bid.item] = int(bid.bid_amount)
    return "User: {0} \nBids: \n{1}".format(bidder, bid_dict)
Ejemplo n.º 2
0
def del_bids(request):
    bidder, item_name = read_request_item(request)
    print bidder,item_name
    bid = get_bid(bidder= bidder, item_name = item_name)
    if bid:
        bid[0].delete()
        message = messages['BID_DELETED_MESSAGE']
    else:
        message = messages['BID_NOT_PRESENT_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 notify(item, username, bid_amount):
    subscribers = []
    bid_list = get_bid(item_name= item)

    for bidder in bid_list:
        users = User.objects.filter(username__exact=bidder.bidder)
        for user in users:
            subscribers.append(user.email)

    subject = "New bid on {}".format(item)
    content = "{} bid amount {} on the item {}".format(username, bid_amount, item)
    message = (subject, content, '*****@*****.**', subscribers) #create constant list
    print message
    print "type", type(message)
    send_mass_mail(message)
Ejemplo n.º 5
0
def notify(item, username, bid_amount):
    subscribers = []
    bid_list = get_bid(item_name=item)

    for bidder in bid_list:
        users = User.objects.filter(username__exact=bidder.bidder)
        for user in users:
            subscribers.append(user.email)

    subject = "New bid on {}".format(item)
    content = "{} bid amount {} on the item {}".format(username, bid_amount,
                                                       item)
    message = (subject, content, '*****@*****.**', subscribers
               )  #create constant list
    print message
    print "type", type(message)
    send_mass_mail(message)
Ejemplo n.º 6
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.º 7
0
def add_bid(request):
    bidder, item_name, amount = read_request_item(request)
    #Check if item is sold
    if is_sold(item_name):
        return messages['SOLD_MESSAGE']
    #search for the bid using bidder and item_name
    bid = get_bid(bidder = bidder, item_name=item_name)
    #if bid is present update the bid amount else create bid
    if bid:
        bid = modify_bid(bid=bid[0], amount=amount)
        bid_action="Modified"
    else:
        bid = create_bid(item = item_name, bidder = bidder, bid_amount= amount)
        bid_action="Created"

    #notify all bidders for this item
    notify(item= item_name, username= bidder, bid_amount= amount)

    return "{0} Bid: {1} {2}".format(bid_action, bid.item, bid.bid_amount)