def view_items(request): seller, item_name = read_request_item(request) item = Items.objects.get(item_name = item_name) date = item.date_added.strftime("%A, %B %d %Y, %H:%M:%S") message= "Item Listed: {0} \\n DateCreated: {1} \\n Status: {2}".format(item.name, date, item.status) if is_sold(item): return HttpResponse(message, status= 200) else: top_bids= Highestbid(N=5, item=item) return HttpResponse(message + "The top 5 bids:\n{2}".format(item.item_name, date, top_bids), status= 200)
def view_items(request): seller, item_name = read_request_item(request) item = Items.objects.get(item_name=item_name) date = item.date_added.strftime("%A, %B %d %Y, %H:%M:%S") message = "Item Listed: {0} \\n DateCreated: {1} \\n Status: {2}".format( item.name, date, item.status) if is_sold(item): return HttpResponse(message, status=200) else: top_bids = Highestbid(N=5, item=item) return HttpResponse( message + "The top 5 bids:\n{2}".format(item.item_name, date, top_bids), status=200)
def view_items(request): seller, item_name = read_request_item(request) item = get_item(item_name) if item: item_name, created_at, status, seller, min_bid, sold_to =values(item) message= "Item Listed: {0} \nDateCreated: {1} \nStatus: {2} \nSeller : {3} \nMinimum Bid: {4} \nSold To: {5}".format(item_name, created_at, status, seller, min_bid, sold_to) else: return messages['ITEM_NOT_PRESENT_MESSAGE'] if is_sold(item): return (message) else: NUMBER_OF_TOP_BIDS= messages['NUMBER_OF_TOP_BIDS'] top_bids= Highestbid(N=NUMBER_OF_TOP_BIDS, item=item) message = message + "\nThe top {0} bids:\n{1}".format(NUMBER_OF_TOP_BIDS, top_bids) return (message)
def view_items(request): seller, item_name = read_request_item(request) item = get_item(item_name) if item: item_name, created_at, status, seller, min_bid, sold_to = values(item) message = "Item Listed: {0} \nDateCreated: {1} \nStatus: {2} \nSeller : {3} \nMinimum Bid: {4} \nSold To: {5}".format( item_name, created_at, status, seller, min_bid, sold_to) else: return messages['ITEM_NOT_PRESENT_MESSAGE'] if is_sold(item): return (message) else: NUMBER_OF_TOP_BIDS = messages['NUMBER_OF_TOP_BIDS'] top_bids = Highestbid(N=NUMBER_OF_TOP_BIDS, item=item) message = message + "\nThe top {0} bids:\n{1}".format( NUMBER_OF_TOP_BIDS, top_bids) return (message)
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)
def add_bid(request): bidder, item_name, amount = read_request_item(request) item = Items.objects.get(item_name = item_name) if is_sold(item): return ("Cannot Bid: {0}. Item already sold".format(item_name)) else: try: bid = bids.objects.get(item = item, bidder = bidder ) except bids.DoesNotExist: bid = bids.objects.create(bidder = bidder, item = item, bid_amount= amount) bid_action="Created" else: bid.bid_amount = amount bid.save(update_fields=['bid_amount']) bid_action="Modified" #function for notifying bidders notify(item= item_name, username= bidder, bid_amount= amount) return ("{0} Bid: {1} {2}".format(bid_action,bid.item.item_name, bid.bid_amount))
def add_bid(request): bidder, item_name, amount = read_request_item(request) item = Items.objects.get(item_name=item_name) if is_sold(item): return ("Cannot Bid: {0}. Item already sold".format(item_name)) else: try: bid = bids.objects.get(item=item, bidder=bidder) except bids.DoesNotExist: bid = bids.objects.create(bidder=bidder, item=item, bid_amount=amount) bid_action = "Created" else: bid.bid_amount = amount bid.save(update_fields=['bid_amount']) bid_action = "Modified" #function for notifying bidders notify(item=item_name, username=bidder, bid_amount=amount) return ("{0} Bid: {1} {2}".format(bid_action, bid.item.item_name, bid.bid_amount))