Beispiel #1
0
    def POST(self):

        post_params = web.input()
        userID = post_params['userID']
        price = post_params['price']
        itemID = post_params['itemID']

        # check the bid price position

        item = sqlitedb.getItemById(itemID)

        if (sqlitedb.getTime() > item['Ends']) or (item['Currently'] >=
                                                   item['Buy_Price']):
            return render_template('add_bid.html', add_result=False)

        try:
            sqlitedb.addBid(itemID, userID, price)
            update_message = 'Bid successfully added'
            return render_template('add_bid.html', add_result=True)
        except TypeError:  # workaround because TypeError on date is not iterable but for some reason still adds to bids
            update_message = 'Bid successfully added'
            return render_template('add_bid.html', add_result=True)
        except Exception as ex:
            print(ex)
            update_message = 'Bid addition failed'
            return render_template('add_bid.html', add_result=False)
Beispiel #2
0
    def POST(self):
        try:
            post_params = web.input()
            userID = post_params['userID']
            itemID = post_params['itemID']
            price = post_params['price']
            currTime = string_to_time(sqlitedb.getTime())

            item = sqlitedb.getItemById(itemID)
            itemPrice = item['Currently']
            itemEndTime = string_to_time(item['Ends'])
            ItemStartTime = string_to_time(item['Started'])
            buyPrice = item['Buy_Price']
            if price <= itemPrice:
                update_message = '(Hi %s, your bid of %s on item %s was unsuccessful because the current bid was higher than your bid.)' % (
                    userID, itemID, price)
            elif currTime > itemEndTime or buyPrice <= itemPrice:
                update_message = '(Hi %s, your bid of %s on item %s was unsuccessful because the auction for this item has ended.)' % (
                    userID, itemID, price)
            elif currTime < itemStartTime:
                update_message = '(Hi %s, your bid of %s on item %s was unsuccessful because the auction for this item has not started yet.)' % (
                    userID, itemID, price)
            else:
                sqlitedb.addBid(userID, itemID, price)
                update_message = '(Hi %s, your bid of %s on item %s was successful!)' % (
                    userID, itemID, price)
        except Exception as e:
            update_message = '(A database error occured: %s)' % (e.message)
        return render_template('add_bid.html', message=update_message)
Beispiel #3
0
    def POST(self):
        post_params = web.input()

        itemID = post_params['itemID']
        price = post_params['price']
        userID = post_params['userID']
        current_time = sqlitedb.getTime()

        ### Many ways to fail... #######################################

        # (1) All fields must be filled
        if (itemID == '') or (price == '') or (userID == ''):
            return render_template('add_bid.html',
                                   message='You must fill out every field')

        item_row = sqlitedb.getItemById(itemID)

        # (2) There must be an item with that ID
        if item_row == None:
            return render_template('add_bid.html',
                                   message='There are no items with that ID')

        # (3) Users can't bid on closed auction items
        if (string_to_time(item_row.EndTime) <= string_to_time(current_time)):
            return render_template('add_bid.html',
                                   message='That auction is already closed')

        # (4) UserID must correspond to an existing user in User table
        user_row = sqlitedb.getUserById(userID)
        if user_row == None:
            return render_template('add_bid.html',
                                   message='There are no users with that ID')

        # (5) Don't accept bids <= current highest bid
        if float(price) <= float(item_row.CurrentBid):
            return render_template(
                'add_bid.html',
                message=
                'You must make a bid higher than the current price (currently $'
                + str(item_row.CurrentBid) + ')')

        ### ... but it's possible to succeed :P ########################

        # A bid at the buy_price closes the auction
        if (item_row.BuyItNow != None and price >= item_row.BuyItNow):
            # Update ends to current_time
            sqlitedb.updateItemEndTime(itemID, current_time)
            return render_template(
                'add_bid.html',
                message=
                'Congratulations! You just closed that auction by making a bid at or above the buy price'
            )

        # Add bid to Bid table in db
        sqlitedb.addBid(itemID, price, userID, current_time)

        return render_template(
            'add_bid.html',
            message='Success! You\'ve just placed a bid on ' + item_row.Name +
            '(' + itemID + ')')
Beispiel #4
0
def add_bid():
    if request.method == 'POST':

        post_params = request.form
        itemID = post_params["itemID"]
        userID = post_params["userID"]
        price = post_params["price"]
        current_time = sqlitedb.getTime()

        if (itemID == '') or (userID == '') or (price == ''):
            return render_template('add_bid.html', add_result = False, message = "Not all field is filled")

        item = sqlitedb.getItemById(itemID)
        print item[7]

        if (item == None):
            return render_template('add_bid.html', add_result = False, message = "Cannot find item")

        if (string_to_time(item[7]) <= string_to_time(current_time)):
            return render_template('add_bid.html', add_result = False, message = "The auction is already Closed")

        user = sqlitedb.getUserById(userID)

        if (user == None):
            return render_template('add_bid.html', add_result = False, message = "Cannot find user")

        if float(price) <= float(item[2]):
            return render_template('add_bid.html', add_result = False, message = "Price is Lower than current price")

        sqlitedb.addBid(userID, price, current_time, itemID)

        return render_template('add_bid.html', add_result = True, message = "Add Bid Successful")
    else:
        return render_template('add_bid.html')
    def POST(self):
        post_params = web.input()
        itemID = post_params['itemID']
        userID = post_params['userID']
        price = post_params['price']

        try:
            sqlitedb.addBid(itemID, userID, price)
        except Exception as e:
            return render_template('add_bid.html',
                                   add_result=False,
                                   error_message=str(e))

        return render_template('add_bid.html', add_result=True)
 def POST(self):
     post_params = web.input()
     if (post_params['itemID'] == ""):
         return render_template('add_bid.html',
                                add_result={
                                    "status": False,
                                    "message": "Invalid Item ID"
                                })
     elif (post_params['userID'] == ""):
         return render_template('add_bid.html',
                                add_result={
                                    "status": False,
                                    "message": "Invalid User ID"
                                })
     elif (post_params['price'] == ""):
         return render_template('add_bid.html',
                                add_result={
                                    "status": False,
                                    "message": "Invalid Buy Price"
                                })
     result = sqlitedb.addBid(post_params)
     if (result):
         return render_template('add_bid.html',
                                add_result={
                                    "status": True,
                                    "message": "Bid was added successfully!"
                                })
     else:
         return render_template(
             'add_bid.html',
             add_result={
                 "status": False,
                 "message": "Add Bid Failed! Try Again with valid inputs!"
             })
Beispiel #7
0
 def POST(self):
     post_params = web.input()
     itemID = post_params['itemID']
     userID = post_params['userID']
     price = post_params['price']
     add_result = sqlitedb.addBid(itemID, userID, price, sqlitedb.getTime())
     return render_template('add_bid.html', add_result=add_result)
 def POST(self):
     post_params = web.input()
     values = {}
     values["itemID"] = post_params["itemID"]
     values["userID"] = post_params["userID"]
     values["price"] = post_params["price"]
     result = sqlitedb.addBid(values)
     return render_template('add_bid.html', message = result[0], add_result = result[1])
Beispiel #9
0
    def POST(self):
        post_params = web.input()
        item_id = post_params['itemID']
        user_id = post_params['userID']
        price = post_params['price']

        result = sqlitedb.addBid(item_id, user_id, price)

        return render_template('add_bid.html', message=result)
Beispiel #10
0
 def POST(self):
     #TODO Ability for auction users to enter bids on open auctions.
     post_params = web.input()
     itemID = post_params['itemID']
     userID = post_params['userID']
     price = post_params['price']
     if (sqlitedb.addBid(itemID, userID, price)):
         return render_template('add_bid.html', add_result=True)
     else:
         return render_template('add_bid.html', add_result=False)
Beispiel #11
0
 def POST(self):
     post_params = web.input()
     itemID = post_params['itemID']
     userID = post_params['userID']
     price = post_params['price']
     result, msg = sqlitedb.addBid(itemID, userID, price)
     if result == -1:
         return render_template('add_bid.html', add_result=False, message=msg)
     else:
         return render_template('add_bid.html', add_result=True)
    def POST(self):
        post_params = web.input()
        itemID = post_params['itemID']
        userID = post_params['userID']
        price = post_params['price']
        returnValue = sqlitedb.addBid(itemID, userID, price)

        msg = returnValue[0]
        add_result = returnValue[1]
        return render_template('add_bid.html',
                               message=msg,
                               add_result=add_result)
Beispiel #13
0
    def POST(self):
        post_params = web.input()
        item_id = post_params['itemid']
        user_id = post_params['userid']
        amount = post_params['amount']
        current_time = sqlitedb.getTime()

        web.debug(item_id)
        web.debug(user_id)
        web.debug(amount)

        t = sqlitedb.transaction()
        try:
            sqlitedb.addBid(item_id, user_id, current_time, amount)
        except:
            t.rollback()
            raise web.seeother('/500?errortype={0}&errorvalue={1}'.format(sys.exc_info()[0], sys.exc_info()[1]))
        else:
            t.commit()

        return render_template('place_bid.html', itemid = item_id, username = session.get('username', None))
Beispiel #14
0
    def POST(self):
        post_params = web.input()
        itemID = post_params['itemID']
        userID = post_params['userID']
        price = post_params['price']

        if (itemID == '' or userID == '' or price == ''):
            return render_template(
                'add_bid.html',
                message='All fields must not be blank to place a bid')
        else:
            result = sqlitedb.addBid(itemID, userID, price)
            return render_template('add_bid.html', add_result=result)
Beispiel #15
0
 def POST(self):
     params = web.input()
     itemID = int(params['itemID'])
     userID = params['userID']
     price = params['price']
     currentTime = sqlitedb.getTime()
     update_message = 'You(userID:%s) have successfully bidded on the item(itemID:%s) for %s dollars' % (
         userID, itemID, price)
     t = sqlitedb.transaction()
     try:
         sqlitedb.addBid(itemID, userID, price, currentTime)
     except Exception as e:
         t.rollback()
         print str(e)
         update_message = str(e)
         return render_template('add_bid.html',
                                message=update_message,
                                add_result=False)
     else:
         t.commit()
         return render_template('add_bid.html',
                                message=update_message,
                                add_result=True)
Beispiel #16
0
    def POST(self):
        post_params = web.input()
        InputArray = {}
        InputArray[0] = post_params["itemID"]
        InputArray[1] = post_params["userID"]
        InputArray[2] = post_params["price"]

        #print(InputArray)
        result = sqlitedb.addBid(InputArray)
        if (result[1]):
            return render_template('add_bid.html',
                                   message=result[0],
                                   add_result=result[1])
        return render_template('add_bid.html', message=result[0])
Beispiel #17
0
    def POST(self):
        post_params = web.input()
        itemID = post_params['itemID']
        userID = post_params['userID']
        price = post_params['price']

        if itemID and userID and price:
            items = sqlitedb.addBid(itemID, userID, price)
            if items:
                good_message = 'You have successfully added a bid!'
                return render_template('add_bid.html', add_result = items, message = good_message)
            else:
                bad_message = 'Your attempt to add a bid violates constraints.'
                return render_template('add_bid.html', add_result = items, message = bad_message)
        else:
            warning_message = 'Please fill out all fields!'
            return render_template('add_bid.html', message = warning_message)
  def POST(self):
    post_params = web.input()

    itemID = post_params['itemID']
    price = post_params['price']
    userID = post_params['userID']
    current_time = sqlitedb.getTime()

    ### Many ways to fail... #######################################

    # (1) All fields must be filled
    if (itemID == '') or (price == '') or (userID == ''):
      return render_template('add_bid.html', 
        message = 'You must fill out every field'
      )

    item_row = sqlitedb.getItemById(itemID)

    # (2) There must be an item with that ID
    if item_row == None:
      return render_template('add_bid.html', 
        message = 'There are no items with that ID'
      )

    # (3) Users can't bid on closed auction items
    if (string_to_time(item_row.ends) <= string_to_time(current_time)):
      return render_template('add_bid.html', 
        message = 'That auction is already closed'
      )

    # (4) UserID must correspond to an existing user in User table
    user_row = sqlitedb.getUserById(userID);
    if user_row == None:
      return render_template('add_bid.html', 
        message = 'There are no users with that ID'
      )

    # (5) Don't accept bids <= current highest bid
    if float(price) <= float(item_row.currently):
      return render_template('add_bid.html', 
        message = 'You must make a bid higher than the current price (currently $' + item_row.currently + ')'
      )

    ### ... but it's possible to succeed :P ########################

    # A bid at the buy_price closes the auction
    if (price >= item_row.buy_price):
      # Update ends to current_time
      sqlitedb.updateItemEndTime(itemID, current_time);
      return render_template(
        'add_bid.html', 
        message = 'Congratulations! You just closed that auction by making a bid at or above the buy price'
      )

    # Add bid to Bid table in db
    sqlitedb.addBid(itemID, price, userID, current_time)

    return render_template(
      'add_bid.html', 
      message = 'Success! You\'ve just placed a bid on ' + item_row.name + '(' + itemID + ')'
    )
Beispiel #19
0
    def POST(self):
        post_params = web.input()

        itemID = post_params['itemID']
        price = post_params['price']
        userID = post_params['userID']
        current_time = sqlitedb.getTime()

        ### Many ways to fail... #######################################
        # (1) All fields must be filled
        if (itemID == '') or (price == '') or (userID == ''):
            return render_template('add_bid.html', message='You must fill out every field')
   
        # (2) There must be an item with that ID
        if not len(sqlitedb.getItemById(itemID)):
            return render_template('add_bid.html', message='There are no items with that ID')
        
        item_row = sqlitedb.getItemById(itemID)[0]
        # (3) Users can't bid on closed auction items
        if (string_to_time(item_row.ends) <= string_to_time(current_time)):
            return render_template('add_bid.html', message='That auction is already closed for time')

        # (4) Users can't bid on auction items that have not been opened
        if (string_to_time(item_row.started) >= string_to_time(current_time)):
            return render_template('add_bid.html', message='That auction has not started yet, Please wait')
        # (4) UserID must correspond to an existing user in User table
        user_row = sqlitedb.getUserById(userID);
        if user_row == None:
            return render_template('add_bid.html', message='There are no users with that ID')
      
        # (5) An user may not bid on an item he or she is also selling
        if userID == item_row.sellerID:
            return render_template('add_bid.html', message='You can not bid on the item you are selling')
        
        # (6) Don't accept bids <= current highest bid
        if float(price) <= float(item_row.currently):
            return render_template('add_bid.html', message='You must make a bid higher than the current price ' 
                               + str(item_row.currently))

        ### ... but it's possible to succeed :P ########################

        # A bid at the buy_price closes the auction
        if(item_row.buyPrice != None):
            if (float(price) >= float(item_row.buyPrice)):
                r1 = sqlitedb.addBid(itemID, price, userID, current_time)
                if r1 != "success":
                    return render_template("add_bid.html", message="ERROR! " + r1)
                # Update ends to current_time
                r2 = sqlitedb.updateItemEndTime(itemID, current_time);
                if r2 != "success":
                   return render_template("add_bid.html", message="ERROR! " + r1) 
                
                return render_template('add_bid.html',
                        message='Congratulations! You just closed that auction by making a bid at or above the buy price',
                        add_result="success")
                
        # Add bid to Bid table in db
        r3 = sqlitedb.addBid(itemID, price, userID, current_time)
        if r3 != "success":
            return render_template("add_bid.html", message="ERROR! " + r3)
        elif r3 == "success":
            return render_template('add_bid.html',
                message='Success! You\'ve just placed a bid on ' + item_row.name + '(' + itemID + ')',
                add_result="success")
Beispiel #20
0
    def POST(self):

        post_params = web.input()
        user_id = post_params['userID']
        item_id = post_params['itemID']
        amount = post_params['price']
        time = sqlitedb.getTime()

        if user_id == '' or item_id == '' or amount == '':
            return render_template('add_bid.html',
                                   message='These fields cannot be empty')

        item = sqlitedb.getItemById(item_id)
        if item is None:
            return render_template('add_bid.html', message='ItemID not match')

        user = sqlitedb.getUserById(user_id)
        if user is None:
            return render_template('add_bid.html', message='UserID not match')

        if amount < 0:
            return render_template('add_bid.html',
                                   message='Price cannot be negative')

        if amount <= item.First_Bid:
            return render_template(
                'add_bid.html',
                message='Price is lower than minimum price seller set')

        if string_to_time(time) >= string_to_time(
                item.Ends) or string_to_time(time) < string_to_time(
                    item.Started):
            return render_template(
                'add_bid.html',
                message=
                'No auction may have a bid before its start time or after its end time.'
            )

        if user_id == item.Seller_UserID:
            return render_template(
                'add_bid.html',
                message=
                'A user may not bid on an item he or she is also selling')

        # TODO: No auction may have two bids at the exact same time. Don't know how to do that

        # not sure if triggers already handled these constraint, if not, we may need to handle in this funciton

        item.Number_of_Bids += 1
        item.Currently = amount

        # Close the auction if amount is greater than buy_price the seller set
        if amount >= item.Buy_Price and item.Buy_Price is not None:
            sqlitedb.updateItem(item_id, time, amount)
            msg = '(Congratulations. Your bid %s achieves the buy_price and this %s is now yours)' % \
                  (amount, item.Name)
        else:
            msg = '(You just added a bid on item %s)' % item.Name

        sqlitedb.addBid(user_id, item_id, amount, time)
        return render_template('add_bid.html', message=msg)