コード例 #1
0
 def GET(self):
     current_time = sqlitedb.getTime()
     if web.input() :
         get_params = web.input()
         itemID = get_params['itemID']
         categories = sqlitedb.getCategory(itemID)
         category=''
         for i in categories:
             print i
             category += i['category']+";"
         if len(sqlitedb.getItemById(itemID)):
             item = sqlitedb.getItemById(itemID)[0]
             stime = item.started
             etime = item.ends
             bids = sqlitedb.getBidsByItemId(itemID)
             status = "Closed"
             if (string_to_time(current_time) >= string_to_time(stime)) and (string_to_time(current_time) <= string_to_time(etime)):
                 status = "Opening"
             if status == "Closed":
                 winner = sqlitedb.getWinnerId(itemID)
                 return render_template('item_detail.html', result=item, status=status, winner=winner, bids=bids,category=category)
             else:
                 return render_template('item_detail.html', result=item, status=status, bids=bids,category=category)
         else:
             return render_template('item_detail.html', error="Sorry, this auction does not exist!")
     else:
         return render_template('item_detail.html')
コード例 #2
0
    def POST(self):
        post_params = web.input()
        item_id = post_params['item_id']
        bid = sqlitedb.getBidsById(item_id)
        item = sqlitedb.getItemById(item_id)
        category = sqlitedb.getCategoryById(item_id)
        time = sqlitedb.getTime()
        buy_price = item['Buy_Price']
        winner = None

        # the bid is open before the end time and when current bid price is lower than buy price
        if time < item['Ends'] and item['Currently'] < buy_price:
            open = True
        # the bid is open when there is no bid
        elif item['Number_of_Bids'] <= 0:
            open = True
        else:
            # get the winner of the item
            winner = sqlitedb.getWinnerById(item_id,
                                            item['Currently'])['UserID']
            open = False

        return render_template('item_info.html',
                               bid_result=bid,
                               item=item,
                               categories=category,
                               open=open,
                               winner=winner)
コード例 #3
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)
コード例 #4
0
    def POST(self):
        post_params = web.input()
        item_id = post_params['item_id']
        bid_result = sqlitedb.getBids(item_id)
        item = sqlitedb.getItemById(item_id)
        categories = sqlitedb.getCategory(item_id)
        current_time = sqlitedb.getTime()
        if item['Buy_Price'] is not None:
            buy_price = item['Buy_Price']
        else:
            buy_price = float('inf')

        winner = None
        if item['Ends'] > current_time and item['Currently'] < buy_price:
            open = True
        else:
            if item['Number_of_Bids'] > 0:
                winner = sqlitedb.getBuyer(item_id,
                                           item['Currently'])['UserID']
            open = False
        return render_template('item.html',
                               bid_result=bid_result,
                               item=item,
                               categories=categories,
                               open=open,
                               winner=winner)
コード例 #5
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 + ')')
コード例 #6
0
ファイル: auctionbase.py プロジェクト: dmaida/EbayProject
    def GET(self):
        itemID = web.input(id='web')
        details = web.websafe(itemID.id)

        q = "select * from Item where itemID = %s" % (details)
        r = "select name from Category where itemID = %s" % (details)
        s = "select userID, amount, currtime from Bid where itemID = %s ORDER BY Bid.amount DESC" % (
            details)

        Q = sqlitedb.query(q)
        R = sqlitedb.query(r)
        S = sqlitedb.query(s)

        current_time = sqlitedb.getTime()

        item_row = sqlitedb.getItemById(details)

        winner = False
        if (string_to_time(item_row.ends) <= string_to_time(current_time)):
            #winner = sqlitedb.getWinnerId(details)
            winner = True

        return render_template('bid_details.html',
                               Item=Q,
                               Cat=R,
                               Bid=S,
                               Win=winner)
コード例 #7
0
 def GET(self, item):
     auction = web.input(item=None)
     detail = sqlitedb.getItemById(auction.item)
     categories = sqlitedb.getCategoriesByItemId(auction.item)
     status = sqlitedb.getStatusByItemId(auction.item)
     bids = sqlitedb.getBidsByItemId(auction.item)
     return render_template('detail.html', status=status, bids=bids, categories=categories, details=detail)
コード例 #8
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)
コード例 #9
0
    def GET(self):
        get_params = web.input()
        itemID = get_params['itemID']

        # get item tuple from item ID
        item = sqlitedb.getItemById(itemID)

        # get bids
        bids = sqlitedb.getBids(itemID)

        # get categories
        categories = sqlitedb.getCategories(itemID)

        # get auction status
        auction_status = sqlitedb.getAuctionStatus(itemID)

        # get winner if auction is closed
        winner = None
        if auction_status == sqlitedb.AuctionStatus.CLOSED:
            winner = sqlitedb.getWinner(itemID)

        return render_template('auction.html',
                               item=item,
                               bids=bids,
                               categories=categories,
                               auction_status=auction_status,
                               winner=winner)
コード例 #10
0
    def GET(self, item_id):
        item_info = sqlitedb.getItemById(item_id)
        category = sqlitedb.getCategoryById(item_id)
        bids = sqlitedb.getBidsById(item_id)

        if item_info is None or category is None or bids is None:
            msg = 'Item_id not match'
            return render_template('search_auction.html', message=msg)

        if string_to_time(curr_time) > string_to_time(item_info.Ends):
            status = 'closed'
            winner = sqlitedb.getWinnerOfAuction(item_id)
        elif string_to_time(curr_time) > string_to_time(item_info.Started):
            status = 'open'
            winner = None
        else:
            status = 'Not Started'
            winner = None

        return render_template('search_auction.html',
                               item=item_info,
                               category=category,
                               status=status,
                               bids=bids,
                               winner=winner)
コード例 #11
0
ファイル: auctionbase.py プロジェクト: shina07/cs360_Database
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')
コード例 #12
0
    def GET(self):
        param = web.input()
        if (len(param) == 0):
            return render_template('single_item_view.html')
        id = param.Id
        item = sqlitedb.getItemById(id)
        if (not item):
            update_message = "No Such Item"
            return render_template('single_item_view.html',
                                   message=update_message)

        # get stuff from items table (category, item, description, etc)
        result = sqlitedb.getItemReWrite(id)

        # get categories of item
        categories = sqlitedb.getItemCategories(id)

        # figure out if the auction is closed or open
        auctionMessage = "Open"
        winning_bidder = None
        if not sqlitedb.hasAuctionStartedSQLOnly(id):
            auctionMessage = "Closed"
        if sqlitedb.hasAuctionEnded(id):
            auctionMessage = "Closed"
            if sqlitedb.getWinningBidder(id) is not None:
                winning_bidder = sqlitedb.getWinningBidder(id)

        bids = sqlitedb.getBids(id)
        if (not bids):
            allBids = []
            if winning_bidder is not None:
                return render_template('single_item_view.html',
                                       results=result,
                                       categories=categories.Category,
                                       auctionMessage=auctionMessage,
                                       winningBidder=winning_bidder)
            return render_template(
                'single_item_view.html',
                results=result,
                categories=categories.Category,
                auctionMessage=auctionMessage,
            )
        else:
            allBids = bids
            print bids[0]['UserID']
            if winning_bidder is not None:
                return render_template('single_item_view.html',
                                       results=result,
                                       categories=categories.Category,
                                       auctionMessage=auctionMessage,
                                       allBids=bids,
                                       winningBidder=winning_bidder)
            return render_template(
                'single_item_view.html',
                results=result,
                categories=categories.Category,
                auctionMessage=auctionMessage,
                allBids=bids,
            )
コード例 #13
0
    def POST(self):
        post_params = web.input()
        itemID = post_params['itemID']
        userID = post_params['userID']
        Amount = post_params['price']

        # Valid search
        if itemID == '' or userID == '' or Amount == '':
            return render_template(
                'add_bid.html',
                message='Error: check valid ItemID, UserID, and Amount')
        else:
            curr_item = sqlitedb.getItemById(itemID)
            curr_user = sqlitedb.getUserById(userID)
        # Valid item in database
        if curr_item is None:
            return render_template('add_bid.html',
                                   message='Error: invalid ItemID')
        # Valid user
        elif curr_user is None:
            return render_template('add_bid.html',
                                   message='Error: invalid UserID')
        # User not bidding on own item
        elif curr_user.UserID == curr_item.Seller_UserID:
            return render_template(
                'add_bid.html', message='Error: User cannot bid on own items')
        # Auction ongoing
        elif string_to_time(sqlitedb.getTime()) >= string_to_time(
                curr_item.Ends):
            return render_template('add_bid.html',
                                   message='Error: auction ended')
        # Auction Started
        elif string_to_time(sqlitedb.getTime()) < string_to_time(
                curr_item.Started):
            return render_template('add_bid.html',
                                   message='Errr: auction yet to start')
        # Valid bid amount
        elif float(Amount) < 0 or float(Amount) <= float(
                curr_item.First_Bid) or float(Amount) <= float(
                    curr_item.Currently):
            return render_template('add_bid.html',
                                   message='Error: invalid amount')
        # Valid buy price
        if curr_item.Buy_Price is not None:
            #close auction if buy price met
            if float(Amount) >= float(curr_item.Buy_Price):
                successful_purchase = 'WOOT! You now own item: %s at the low low price of: %s.' % (
                    curr_item.Name, Amount)
                return render_template('add_bid.html',
                                       message=successful_purchase,
                                       add_result=sqlitedb.new_bid(
                                           itemID, userID, Amount))
        #Verified no errors exist, place a new bid on the item for the amount specified
        successful_bid = 'You have bid on the amazing: %s at the low low price of: %s.' % (
            curr_item.Name, Amount)
        return render_template('add_bid.html',
                               message=successful_bid,
                               add_result=sqlitedb.new_bid(
                                   itemID, userID, Amount))
コード例 #14
0
    def POST(self):
        current_time = sqlitedb.getTime()
        post_params = web.input()
        itemID = post_params['itemID']
        userID = post_params['userID']
        price = float(post_params['price'])

        if sqlitedb.getUser(userID):
            if sqlitedb.getItemById(itemID) is None:
                result = False
                update_message = 'Item is invalid'
                return render_template('add_bid.html',
                                       add_result=result,
                                       message=update_message)
            else:
                if sqlitedb.bidisOpen(itemID):
                    t = sqlitedb.transaction()
                    query_string = 'INSERT INTO Bids (itemID, UserID, Amount, Time) VALUES ($itemID, $userid, $price, $time) '
                    try:
                        if user_id == '' or item_id == '' or amount == '':
                            return render_template('add_bid.html',
                                                   message='empty fields')
                        sqlitedb.query(
                            query_string, {
                                'itemID': itemID,
                                'userid': userID,
                                'price': price,
                                'time': current_time
                            })
                    except Exception as e:
                        t.rollback()
                        print str(e)
                        update_message = 'An error has occurred'
                        result = False
                        return render_template('add_bid.html',
                                               add_result=result,
                                               message=update_message)
                    else:
                        t.commit()
                        update_message = 'Add bid successfully!'
                        result = True
                        return render_template('add_bid.html',
                                               add_result=result,
                                               message=update_message)
                else:
                    update_message = 'Bid is closed'
                    result = False
                    return render_template('add_bid.html',
                                           add_result=result,
                                           message=update_message)
        else:
            result = False
            update_message = 'User is invalid'
            return render_template('add_bid.html',
                                   add_result=result,
                                   message=update_message)
コード例 #15
0
 def GET(self):
     get_params = web.input()
     itemID = get_params["itemID"]
     item = sqlitedb.getItemById(itemID)
     if item == None:
         message = "This item doesn't exist!"
         return render_template('item.html', message = message)
     itemInfo = sqlitedb.getItemInfo(item) 
     message = str(itemInfo)
     return render_template('item.html', item = item, status = itemInfo[0], winner = itemInfo[1], bids = itemInfo[2])
コード例 #16
0
    def POST(self):
        try:
            post_params = web.input()
            add_result = ''
            item_id = post_params['itemID']
            price = post_params['price']
            user_id = post_params['userID']
            current_time = sqlitedb.getTime()

            # Validation checks

            # make all input fields required
            if (item_id == '' or price == '' or user_id == ''):
                return render_template(
                    'add_bid.html', message='Error: All fields are required')

            # don't accept bids on items that don't exist
            if (sqlitedb.getItemById(item_id) == None):
                return render_template('add_bid.html',
                                       message='Error: Invalid Item ID !')

            # Don't accept bids from users that don't exist
            if (sqlitedb.getUserById(user_id) == None):
                return render_template('add_bid.html',
                                       message='Error: Invalid User ID !')

            # @TODO: add more validation checks

            # insert transaction
            t = sqlitedb.transaction()
            try:
                sqlitedb.db.insert('Bids',
                                   ItemID=item_id,
                                   UserID=user_id,
                                   Amount=price,
                                   Time=current_time)

            except Exception as e:
                t.rollback()
                message = str(e)
                print str(e)

            else:
                t.commit()
                message = 'Success ! Added bid for ' + str(
                    item_id) + ' by ' + str(user_id) + ' at $' + str(price)
                print 'commited ' + str(t)
                # @TODO validations

        except Exception as e:
            message = str(e)

        return render_template('add_bid.html',
                               message=message,
                               add_result=add_result)
コード例 #17
0
 def GET(self):
     get_params = web.input()
     itemID = get_params["itemID"]
     item = sqlitedb.item(itemID)
     message = str(item)
     return render_template('item.html',
                            item=sqlitedb.getItemById(itemID),
                            status=item[0],
                            winner=item[1],
                            bids=item[2],
                            categories=item[3])
コード例 #18
0
ファイル: auctionbase.py プロジェクト: richardtai/auctionbase
 def POST(self):
     global item
     post_params = web.input()
     item_found = None
     if (post_params['item-id'] is not None):
         item_id = post_params['item-id']
         item_found = sqlitedb.getItemById(item_id)
     #TODO: Auction closed boolean
     if(item_found is None):
         return render_template('search.html', item = None, loggedIn = loggedIn, user = user)
     else:
         updateCurrentItemMap(item_id)
         return render_template('search.html', item = item, loggedIn = loggedIn, user = user)
コード例 #19
0
 def POST(self):
     post_params = web.input()
     itemID = post_params['itemID']
     userID = post_params['userID']
     category = post_params['category']
     itemDesc = post_params['itemDesc']
     minPrice = post_params['minPrice']
     maxPrice = post_params['maxPrice']
     status = post_params['status']
     t = sqlitedb.transaction()
     try:
         Items = sqlitedb.search(itemID, userID, category, itemDesc,
                                 maxPrice, minPrice, status)
         result = {}
         item_list = []
         category_list = []
         Bid_list = []
         winner_list = []
         for itemID in Items:
             item = sqlitedb.getItemById(itemID)
             item_list.append(item)
             category_list.append(sqlitedb.getCategoryByID(itemID))
             currTime = sqlitedb.getTime()
             #check if buy_price is reached
             if item.Buy_Price != None and item.Buy_Price <= item.Currently and item.Number_of_Bids != 0:
                 status = "Closed"
             else:
                 if currTime < item.Started:
                     status = 'NotStarted'
                 elif currTime > item.Ends:
                     status = 'Closed'
                 else:
                     status = 'Open'
             Bid_list.append(sqlitedb.getBidsByID(itemID))
             winner = None
             if status == 'Closed':
                 winner = sqlitedb.getWinnerByID(itemID)
             winner_list.append(winner)
             #print(map(itemgetter('Category'), sqlitedb.getCategoryByID(itemID)))
     except Exception as e:
         t.rollback()
         print(str(e))
         return render_template('search.html', message=str(e))
     else:
         t.commit()
         return render_template('search_result.html',
                                Item=item_list,
                                Categories=category_list,
                                status=status,
                                Bids=Bid_list,
                                Winner=winner_list)
コード例 #20
0
    def GET(self, items):
        print('The item id is = ', int(items))
        itemID = int(items)

        tempItem = sqlitedb.getItemById(itemID)

        # the item attributes are already present

        # get the categories for the item
        tempItem['Categories'] = sqlitedb.getCategory(itemID)

        # determine the auctions open/close status
        # check if the item is still open
        if (string_to_time(tempItem['Started']) <= string_to_time(
                sqlitedb.getTime())) and (string_to_time(
                    tempItem['Ends']) >= string_to_time(
                        sqlitedb.getTime())) and (tempItem['Buy_Price'] >
                                                  tempItem['Currently']):
            tempItem['Status'] = 'Open'
        # check if the item is closed
        elif (string_to_time(tempItem['Ends']) < string_to_time(
                sqlitedb.getTime())) or (tempItem['Buy_Price'] <=
                                         tempItem['Currently']):
            tempItem['Status'] = 'Close'
        # check if the auction for the item has not started
        elif string_to_time(tempItem['Started']) > string_to_time(
                sqlitedb.getTime()):
            tempItem['Status'] = 'Not Started'

        # determine winner if the auction is closed, determine bids if auction is open
        if tempItem['Status'] == 'Close':
            try:
                win = sqlitedb.getAuctionWinner(itemID)
                tempItem['Winner'] = win
            except:
                tempItem['Winner'] = "No Winners"

        bids = sqlitedb.getBids(itemID)
        bidderList = []
        for b in bids:
            bidderList.append({
                'UserID': b['UserID'],
                'Amount': b['Amount'],
                'Time': b['Time']
            })
            # bidderList.append() "Bidder: " + b['UserID'] + " , Price: " + str(b['Amount']) + " --- Time of Bid: " + b['Time'] + '  |  '
        tempItem['Bids'] = bidderList

        results = [tempItem]

        return render_template('show_item.html', search_result=results)
コード例 #21
0
ファイル: auctionbase.py プロジェクト: yunhezhang/SQL-design
    def POST(self):
        params = web.input()
        itemID = params['itemID']
        userID = params['userID']
        minPrice = params['minPrice']
        maxPrice = params['maxPrice']
        status = params['status']
        category = params['category']
        description = params['description']
        currTime = sqlitedb.getTime()

        if itemID != "":
            t = sqlitedb.transaction()
            result1 = sqlitedb.getItemByStatus(status, currTime)
            try:
                myresult = sqlitedb.getItemById(itemID)
            except Exception as e:
                t.rollback()
                print str(e)
                update_message = 'No item found.'

                return render_template('search.html',
                                       search_result=False,
                                       message=update_message)
            else:
                t.commit()
                result = merge(myresult, result1)
                return render_template('search.html', search_result=result)
        else:
            t = sqlitedb.transaction()
            try:
                result1 = sqlitedb.getItemByUserID(userID)
                result2 = sqlitedb.getItemByPrice(minPrice, maxPrice)
                result3 = sqlitedb.getItemByStatus(status, currTime)
                result4 = sqlitedb.getItemByCategory(category)
                result5 = sqlitedb.getItemByDescription(description)
            except Exception as e:
                t.rollback()
                print str(e)
                return render_template('search.html', message=str(e))
            else:
                m1 = merge(result1, result2)
                m2 = merge(m1, result3)
                m3 = merge(m2, result4)
                result = merge(m3, result5)
                if result == []:
                    update_message = 'No Item found.'
                    return render_template('search.html',
                                           message=update_message)
                else:
                    return render_template('search.html', search_result=result)
コード例 #22
0
    def POST(self):
        post_params = web.input()
        itemID = post_params['itemID']
        itemInfo = sqlitedb.getItemById(itemID)
        categories = sqlitedb.getItemCategories(itemID)
        bids = sqlitedb.getItemBids(itemID)
        winner = sqlitedb.getWinner(itemID)

        return render_template('item_detail.html',
                               itemID=itemID,
                               itemInfo=itemInfo,
                               Categories=categories,
                               Bids=bids,
                               Winner=winner)
コード例 #23
0
    def GET(self, itemID):

        current_time = sqlitedb.getTime()

        item_row = sqlitedb.getItemById(itemID)
        is_open = current_time < item_row.ends
        bids = sqlitedb.getBidsByItemId(itemID)
        winner = str(sqlitedb.getWinnerId(itemID))

        return render_template('view_item.html',
                               item=item_row,
                               is_open=is_open,
                               bids=bids,
                               winner=winner)
コード例 #24
0
    def GET(self):
        post_params = web.input()
        itemID = post_params['id']
        item = sqlitedb.getItemById(itemID)
        categories = sqlitedb.getCategoryById(itemID)
        bids = sqlitedb.getBidById(itemID)
        ended = False
        hasBuyPrice = False
        buyPrice = ""
        winner = ""

        if item.Started <= sqlitedb.getTime(
        ) and item.Ends >= sqlitedb.getTime():
            status = 'Currently Open'
        elif item.Started > sqlitedb.getTime():
            status = 'Has Not Started'
        else:
            status = 'Closed'
        if item.Number_of_Bids == 0: noBids = True
        else:
            noBids = False
            winner = sqlitedb.getWinnerById(itemID).UserID

        if item.Buy_Price is not None:
            hasBuyPrice = True
            buyPrice = item.Buy_Price
            if status == 'Closed' or float(item.Currently) >= float(
                    item.Buy_Price):
                status = 'Closed'
                ended = True
        elif status == 'Closed':
            ended = True

        return render_template('items.html',
                               id=itemID,
                               bids=bids,
                               Name=item.Name,
                               Category=categories.Category,
                               Ends=item.Ends,
                               Started=item.Started,
                               Number_of_Bids=item.Number_of_Bids,
                               Seller=item.Seller_UserID,
                               Description=item.Description,
                               Currently=item.Currently,
                               noBids=noBids,
                               ended=ended,
                               Status=status,
                               Winner=winner,
                               buyPrice=buyPrice,
                               hasBuyPrice=hasBuyPrice)
コード例 #25
0
 def POST(self):
     current_time = sqlitedb.getTime()
     post_params = web.input()
     itemID = post_params['itemID']
     userID = post_params['userID']
     price = float(post_params['price'])
     
     # if the user is valid
     if sqlitedb.getUserByUserId(userID):
         # if the item is valid
         if sqlitedb.getItemById(itemID) is not None:
             # if the bid is active
             if sqlitedb.isBidActive(itemID):
                 t = sqlitedb.transaction()
                 query_string = 'INSERT INTO Bids (itemID, UserID, Amount, Time) VALUES ($itemID, $userID, $price, $time) '
                 try:
                     if itemID == '':
                         return render_template('add_bid.html', message = 'no itemID')
                     if userID == '':
                         return render_template('add_bid.html', message = 'no userID')
                     if price == '':
                         return render_template('add_bid.html', message = 'no amount')
                     sqlitedb.query(query_string, {'itemID': itemID, 'userid': userID, 'price': price, 'time': current_time})
                 except Exception as exception:
                     t.rollback()
                     print str(exception)
                     result = False
                     update_message = 'Error when add a bid'
                     return render_template('add_bid.html', add_result = result, message = update_message)
                 else:
                     t.commit()
                     result = True
                     update_message = 'Successfully add a bid'
                     return render_template('add_bid.html', add_result = result, message = update_message)
             # if the bid is not active
             else:
                 result = False
                 update_message = 'The bid is closed now'
                 return render_template('add_bid.html', add_result = result, message = update_message)
         # if the item can't be found
         else:
             result = False
             update_message = 'Cannot get the item with item id'
             return render_template('add_bid.html', add_result = result, message = update_message)
     # if the user can't be found
     else:
         result = False
         update_message = 'Cannot get the user with user id'
         return render_template('add_bid.html', add_result = result, message = update_message)
コード例 #26
0
    def POST(self):
        #get user input on userID, itemID, and bid amount
        post_params = web.input()
        userID = post_params['userID']
        itemID = post_params['itemID']
        Amount = post_params['price']

        #error check if all values were input
        if userID == '' or itemID == '' or Amount == '':
            return render_template('add_bid.html', message = 'At least one of the following is invalid: UserID, ItemID, or Amount.')
        else:
            #if all values present, retrieve the specified users and items if possible
            curr_user = sqlitedb.getUserById(userID)
            curr_item = sqlitedb.getItemById(itemID)
        
        #if the specified user doesn't exist:
        if curr_user is None:
            return render_template('add_bid.html', message = 'Could not find user with UserID.')
        #if the specified user is the item's seller:
        elif curr_user.UserID == curr_item.Seller_UserID:
            return render_template('add_bid.html', message = 'UserID is the ID of the seller, cannot bid.')
        #if the specified item doesn't exist:
        elif curr_item is None:
            return render_template('add_bid.html', message = 'Could not find item with ItemID.')
        #if the specified amount is negative:
        elif float(Amount) < 0:
            return render_template('add_bid.html', message = 'The specified amount is negative.')
        #if the specified amount is less than the currently highest bid price:
        elif float(Amount) <= float(curr_item.First_Bid) or float(Amount) <= float(curr_item.Currently):
            return render_template('add_bid.html', message = 'The specified amount is too small.')
        #if the specified auction has not yet started:
        elif string_to_time(sqlitedb.getTime()) < string_to_time(curr_item.Started):
            return render_template('add_bid.html', message = 'The auction has not yet started.')
        #if the specified auction has already ended:
        elif string_to_time(sqlitedb.getTime()) >= string_to_time(curr_item.Ends):
            return render_template('add_bid.html', message = 'The auction has already ended.')

        #If the auction has a specified buy price:
        if curr_item.Buy_Price is not None:
            #if specified amount is greater than or equal to buy price:
            if float(Amount) >= float(curr_item.Buy_Price):
                #indicate that the auction has been purchased, and close the auction (IF SUCCESSFUL).
                #On the website, if the Result specifies "not successful", then this step has not been successful due to constraints.
                successful_purchase = 'You have purchased item: %s for: %s. NOTE: Check Result below to see if it was successful.' % (curr_item.Name, Amount)
                return render_template('add_bid.html', message = successful_purchase, add_result = sqlitedb.newBid(userID, itemID, Amount))

        #place a new bid on the item with the specified amount
        successful_bid = 'You have placed a bid on item: %s for: %s. NOTE: Check Result below to see if it was successful.' % (curr_item.Name, Amount)
        return render_template('add_bid.html', message = successful_bid, add_result = sqlitedb.newBid(userID, itemID, Amount))
コード例 #27
0
  def GET(self, itemID):
    
    current_time = sqlitedb.getTime()
    
    item_row = sqlitedb.getItemById(itemID)
    is_open = current_time < item_row.ends
    bids = sqlitedb.getBidsByItemId(itemID)
    winner = str(sqlitedb.getWinnerId(itemID))

    return render_template('view_item.html', 
      item = item_row, 
      is_open = is_open,
      bids = bids,
      winner = winner
    )
コード例 #28
0
 def POST(self):
     post_param = web.input()
     itemID = post_param['itemID']
     userID = post_param['userID']
     category = post_param['category']
     description = post_param['description']
     minPrice = post_param['minPrice']
     maxPrice = post_param['maxPrice']
     status = post_param['status']
     items = sqlitedb.getItemById(itemID, userID, category, description, minPrice, maxPrice, status)
     if items:
         good_message = 'The following results are found!'
         return render_template('search.html', search_result = items, message = good_message)
     else:
         bad_message = 'Sorry, no matching items.'
         return render_template('search.html', search_result = items, message = bad_message)
コード例 #29
0
 def POST(self):
     post_params = web.input()
     itemID = post_params['itemID']
     result = sqlitedb.getItemById(itemID)
     category = sqlitedb.getCategoryById(itemID)
     bid = sqlitedb.getBidById(itemID)
     status = sqlitedb.getStatusById(itemID)
     auctionWinner = None
     if (status == 'close'):
         auctionWinner = sqlitedb.auctionGetter(itemID)
     return render_template('item.html',
                            itemID=itemID,
                            result=result,
                            category=category,
                            bid=bid,
                            status=status,
                            auctionWinner=auctionWinner)
コード例 #30
0
    def POST(self, item):

        post_params = web.input()
        itemID = post_params['itemID']
        # get the item
        tempItem = sqlitedb.getItemById(itemID)

        # the item attributes are already present

        # get the categories for the item
        tempItem['Categories'] = sqlitedb.getCategory(itemID)

        # determine the auctions open/close status
        # check if the item is still open
        if (string_to_time(tempItem['Started']) <= string_to_time(
                sqlitedb.getTime())) and (string_to_time(
                    tempItem['Ends']) >= string_to_time(
                        sqlitedb.getTime())) and (tempItem['Buy_Price'] >
                                                  tempItem['Currently']):
            tempItem['Status'] = 'Open'
        # check if the item is closed
        elif (string_to_time(tempItem['Ends']) < string_to_time(
                sqlitedb.getTime())) or (tempItem['Buy_Price'] <=
                                         tempItem['Currently']):
            tempItem['Status'] = 'Close'
        # check if the auction for the item has not started
        elif string_to_time(tempItem['Started']) > string_to_time(
                sqlitedb.getTime()):
            tempItem['Status'] = 'Not Started'

        # determine winner if the auction is closed, determine bids if auction is open
        if tempItem['Status'] == 'Close':
            win = sqlitedb.getAuctionWinner(itemID)
            tempItem['Winner'] = win

        bids = sqlitedb.getBids(itemID)
        bidderList = ""
        for b in bids:
            bidderList += "Bidder: " + b['UserID'] + " --- Price: " + str(
                b['Amount']) + " --- Time of Bid: " + b['Time'] + '  |  '
        tempItem['Bids'] = bidderList

        results = [tempItem]

        return render_template('show_item.html', search_result=results)
コード例 #31
0
    def GET(self):
        post_params = web.input()
        itemID = post_params['itemID']
        result = sqlitedb.getItemById(itemID)
        isAuctionClosed = False
        latestBid = None
        if (sqlitedb.getTime() > result['Ends']
                or result['Currently'] >= result['Buy_Price']):
            isAuctionClosed = True
            latestBid = sqlitedb.getLatestBidByItemID(itemID)
        bids = sqlitedb.getAllBidsByItemID(post_params['itemID'])
        categories = sqlitedb.getAllCategoriesByItemID(post_params['itemID'])

        return render_template('item_detail.html',
                               item=result,
                               isAuctionClosed=isAuctionClosed,
                               latestBid=latestBid,
                               bids=bids,
                               categories=categories)
コード例 #32
0
    def GET(self):
        #get the user's input on a specific item ID.
        post_params = web.input()
        itemID = post_params['id']

        #retrieve status and bidding information for the specific itemID
        item = sqlitedb.getItemById(itemID)
        categories = sqlitedb.getCategoryById(itemID)
        bids = sqlitedb.getBidById(itemID)

        #initialize items to not yet ended and no buy price, and therefore, no winner
        ended = False
        hasBuyPrice = False
        winner = ""
        buyPrice = ""

        #check and update the status of the auction
        if item.Started <= sqlitedb.getTime() and item.Ends >= sqlitedb.getTime():
            status = 'Still open'
        elif item.Started > sqlitedb.getTime():
            status = 'Not yet started'
        else:
            #at this point, item's end time is already after current time
            status = 'Ended'

        #get a winner if one exists
        if item.Number_of_Bids == 0:
            noBids = True
        else:
            noBids = False
            winner = sqlitedb.getWinnerById(itemID).UserID

        #if bid price is higher than buy price, then close the auction
        if item.Buy_Price is not None:
            hasBuyPrice = True
            buyPrice = item.Buy_Price
            if status == 'Ended' or float(item.Currently) >= float(item.Buy_Price):
                status = 'Ended'
                ended = True
        elif status == 'Ended':
            ended = True

        return render_template('items.html', id = itemID, bids = bids, Name = item.Name, Category = categories.Category, Ends = item.Ends, Started = item.Started, Number_of_Bids = item.Number_of_Bids, Seller = item.Seller_UserID, Description = item.Description, Currently = item.Currently, noBids = noBids, ended = ended, Status = status, Winner = winner, buyPrice = buyPrice, hasBuyPrice = hasBuyPrice)
コード例 #33
0
ファイル: auctionbase.py プロジェクト: kmui2/Web-Auctionbase
 def POST(self):
     params = web.input()
     id = params['id']
     # need to query the database using the id to find all data that we need to display
     item = sqlitedb.getItemById(id)
     categories = sqlitedb.getCategoriesForItemId(id)
     bids = sqlitedb.getBidsForItemId(id)
     status = sqlitedb.getAuctionStatusForItemId(id)
     winner = 'Auction Still Open or Not Opened'
     if status == 'Closed':
         winner = sqlitedb.getWinnerForItemId(id)
         if winner == None:
             winner = 'There is no winner because there were no bids.'
     return render_template('view_auction.html',
                            id=id,
                            item=item,
                            categories=categories,
                            bids=bids,
                            status=status,
                            winner=winner)
コード例 #34
0
ファイル: auctionbase.py プロジェクト: richardtai/auctionbase
def updateCurrentItemMap(item_id):
    global item
    current_time = sqlitedb.getTime()   
    item_found = sqlitedb.getItemById(item_id)
    item['id'] = item_found.id
    item['name'] = HTMLParser.HTMLParser().unescape(item_found.name)
    item['current_bid'] = item_found.current_bid
    item['buy_price'] = item_found.buy_price
    item['first_bid'] = item_found.first_bid
    item['num_bids'] = item_found.num_bids
    item['start'] = item_found.start
    item['end'] = item_found.end
    item['user_id'] = item_found.user_id
    item['description'] = HTMLParser.HTMLParser().unescape(item_found.description)
    if (string_to_time(str(item_found.end)) < string_to_time(str(current_time)) or (item_found.current_bid >= item_found.buy_price and item_found.buy_price is not None) or string_to_time(str(item_found.start)) < string_to_time(str(current_time))):
        item['isOpen'] = False
        # Need to account if the query does not return anything!
        item['winner'] = sqlitedb.getAuctionWinner(item['id'])
    else:
        item['isOpen'] = True
コード例 #35
0
    def GET(self):
        item_id = web.input(itemid=None).itemid
        if item_id is None:
            return render_template('find_auction.html', username = session.get('username', None))
        else:
            # check the status of the current auction
            current_time = sqlitedb.getTime()
            item = sqlitedb.getItemById(item_id)

            if item is None:
                return render_template('find_auction.html', status = "NOT FOUND", username = session.get('username', None))


            # calculate current price
            current_price = sqlitedb.getCurrentPrice(item_id, current_time)
            if current_price is None:
                current_price = item.First_Bid
            item.Currently = current_price

            web.debug(item.Currently)
            web.debug(item.Buy_Price)

            # check the current status of the auction
            status = getAuctionStatus(current_time, item.Started, item.Ends, item.Currently, item.Buy_Price)
            if status == "NOT FOUND":
                return render_template('find_auction.html', status = status, username = session.get('username', None))

            # modify values inside item to make it consistent with the current timestamp
            bids = sqlitedb.getBidsByItemID(item_id, current_time)
            categories = sqlitedb.getCategoryByItemID(item_id)
            if status == "OPEN":
                number_of_bids = sqlitedb.getNumberOfBids(item_id, current_time)
                
                item.Number_of_Bids = number_of_bids
                item.Currently = current_price
                return render_template('find_auction.html', item = item, categories = categories, bids = bids, status = status, username = session.get('username', None))
            else:
                winner = sqlitedb.getWinner(item_id)
                return render_template('find_auction.html', item = item, categories = categories, bids = bids, status = status, winner = winner, username = session.get('username', None))
コード例 #36
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.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 + ')'
    )