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_items(request):
    seller, item_name = read_request_item(request)
    try:
        Items.objects.get(item_name = item_name, seller= seller).delete()
    except Items.DoesNotExist:
        return HttpResponse("Item {0} not present".format(item_name), status= 200)
    else:
        return HttpResponse("Item deleted {0}".format(item_name), status= 200)
Ejemplo n.º 3
0
def add_items(request):
    seller, item_name, min_bid =read_request_item(request)
    print seller, item_name, min_bid
    #item = add_item(seller, item_name, min_bid)
    item = get_item(item_name=item_name)
    exec_time= datetime.now() + timedelta(hours = 1)
    s.addjob(function=sell_items, time= exec_time, arguments=[request, item])
    return ("Added Item: {0} {1}".format(item.item_name, item.__dict__))
Ejemplo n.º 4
0
def view_bids(request):
    bidder, item_name = read_request_item(request)
    bid_dict={}
    bid_list = bids.objects.filter(bidder__exact = bidder)
    for bid in bid_list:
          bid_dict[bid.item.item_name]= int(bid.bid_amount)

    return ("User: {0} \nBids: \n{1}".format(bidder, bid_dict))
Ejemplo n.º 5
0
def del_bids(request):
    bidder, item_name = read_request_item(request)
    try:
        bids.objects.get(item__item_name__exact = item_name, bidder__exact = bidder).delete()
    except bids.DoesNotExist:
        return ("Error: could not delete bid {0}. Bid not present".format(item_name))
    else:
        return ("Bid deleted for {0} ".format(item_name))
Ejemplo n.º 6
0
def add_items(request):
    seller, item_name, min_bid = read_request_item(request)
    print seller, item_name, min_bid
    #item = add_item(seller, item_name, min_bid)
    item = get_item(item_name=item_name)
    exec_time = datetime.now() + timedelta(hours=1)
    s.addjob(function=sell_items, time=exec_time, arguments=[request, item])
    return ("Added Item: {0} {1}".format(item.item_name, item.__dict__))
Ejemplo n.º 7
0
def view_bids(request):
    bidder, item_name = read_request_item(request)
    bid_dict = {}
    bid_list = bids.objects.filter(bidder__exact=bidder)
    for bid in bid_list:
        bid_dict[bid.item.item_name] = int(bid.bid_amount)

    return ("User: {0} \nBids: \n{1}".format(bidder, bid_dict))
Ejemplo n.º 8
0
def del_items(request):
    user, item_name = read_request_item(request)
    item = is_owner(item=item_name, user=user)
    if item:
        item.delete()
        message = "Item {0} deleted".format(item_name)
    else:
        message= messages['CANNOT_PERFORM_ACTION']
    return message
Ejemplo n.º 9
0
def del_items(request):
    user, item_name = read_request_item(request)
    item = is_owner(item=item_name, user=user)
    if item:
        item.delete()
        message = "Item {0} deleted".format(item_name)
    else:
        message = messages['CANNOT_PERFORM_ACTION']
    return message
Ejemplo n.º 10
0
def del_items(request):
    seller, item_name = read_request_item(request)
    try:
        Items.objects.get(item_name=item_name, seller=seller).delete()
    except Items.DoesNotExist:
        return HttpResponse("Item {0} not present".format(item_name),
                            status=200)
    else:
        return HttpResponse("Item deleted {0}".format(item_name), status=200)
Ejemplo n.º 11
0
def add_items(request):
    seller, item_name, min_bid = read_request_item(request)
    item = Items.objects.create(item_name=item_name,
                                seller=seller,
                                date_added=datetime.now(),
                                min_bid=min_bid)
    exec_time = datetime.now() + timedelta(minutes=1)
    s.addjob(function=sell_items, time=exec_time, arguments=[item])
    return HttpResponse("Added Item: {0}".format(item.item_name), status=200)
Ejemplo n.º 12
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.º 13
0
def del_bids(request):
    bidder, item_name = read_request_item(request)
    try:
        bids.objects.get(item__item_name__exact=item_name,
                         bidder__exact=bidder).delete()
    except bids.DoesNotExist:
        return ("Error: could not delete bid {0}. Bid not present".format(
            item_name))
    else:
        return ("Bid deleted for {0} ".format(item_name))
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
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.º 16
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.º 17
0
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)
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
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)
Ejemplo n.º 21
0
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))
Ejemplo n.º 22
0
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))
Ejemplo n.º 23
0
def add_items(request):
    seller, item_name, min_bid = read_request_item(request)
    item= Items.objects.create(item_name = item_name, seller = seller, date_added = datetime.now(), min_bid = min_bid )
    exec_time= datetime.now() + timedelta(minutes = 1)
    s.addjob(function=sell_items, time= exec_time, arguments=[item])
    return HttpResponse("Added Item: {0}".format(item.item_name), status= 200)