def GET(self): id = web.input()['id'] item = sqlitedb.searchItem(id)[0] bids = sqlitedb.getBids(id) item['Category'] = ', '.join(sqlitedb.getCategory(id)) # check status cur_time = sqlitedb.getTime() if cur_time < item['Started']: item['Status'] = 'Not Started' elif cur_time > item['Ends'] or ( item['Buy_Price'] is not None and float(item['Currently']) >= float(item['Buy_Price'])): item['Status'] = 'Close' else: item['Status'] = 'Open' if len(bids) == 0 or item['Status'] is not 'Close': winner = [] else: winner = max(bids, key=lambda bid: bid['Amount']) return render_template('item.html', item=item, bids=bids, winner=winner)
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)
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')
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)
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)
def POST(self): post_params = web.input() item_id = post_params['item_id'] bid = sqlitedb.getBids(item_id) item = sqlitedb.getItemById(item_id) category = sqlitedb.getCategory(item_id) time = sqlitedb.getTime() price = item['Buy_Price'] winner = None if item['Ends'] > time and item['Currently'] < price: open = True else: if item['Number_of_Bids'] > 0: winner = sqlitedb.getWinner(item_id, item['Currently'])['UserID'] open = False return render_template('auction_detail.html', bid_result=bid, item=item, categories=category, open=open, winner=winner)
def POST(self): post_params = web.input() status = post_params['status'] # - itemID = post_params['itemID'] # - minPrice = post_params['minPrice'] # - maxPrice = post_params['maxPrice'] # - category = post_params['category'] # - description = post_params['description'] # - userID = post_params['userID'] results = [] # narrow down search results based on status statusSearch_Temp = sqlitedb.searchOnStatus(status) # print(statusSearch_Temp) statusSearchResults = set( ) # statusSearchResults contains a bunch of Ids for r in statusSearch_Temp: statusSearchResults.add(r['ItemID']) # Filter by ItemID if itemID != '': itemIDSearch_Temp = sqlitedb.searchOnItemID(itemID) itemIDSearchResults = set() for r in itemIDSearch_Temp: itemIDSearchResults.add(r['ItemID']) statusSearchResults = statusSearchResults.intersection( itemIDSearchResults) # print(itemIDSearchResults) if userID != '': userIDSearch_Temp = sqlitedb.searchOnUserID(userID) userIDSearchResults = set() for r in userIDSearch_Temp: userIDSearchResults.add(r['ItemID']) statusSearchResults = statusSearchResults.intersection( userIDSearchResults) # Filter by minPrice if minPrice != '': minPrice_Temp = sqlitedb.searchOnMinPrice(minPrice) minPriceSearchResults = set() for r in minPrice_Temp: minPriceSearchResults.add(r['ItemID']) statusSearchResults = statusSearchResults.intersection( minPriceSearchResults) # filter by maxPrice if maxPrice != '': maxPrice_Temp = sqlitedb.searchOnMaxPrice(maxPrice) maxPriceSearchResults = set() for r in maxPrice_Temp: maxPriceSearchResults.add(r['ItemID']) statusSearchResults = statusSearchResults.intersection( maxPriceSearchResults) # filter by Category if category != '': category_Temp = sqlitedb.searchOnCategory(category) categorySearchResults = set() for r in category_Temp: categorySearchResults.add(r['ItemID']) statusSearchResults = statusSearchResults.intersection( categorySearchResults) # filter by description if description != '': description = '%' + description + '%' description_Temp = sqlitedb.searchOnDescription(description) descriptionSearchResults = set() for r in description_Temp: descriptionSearchResults.add(r['ItemID']) statusSearchResults = statusSearchResults.intersection( descriptionSearchResults) # print(statusSearchResults) final_items = [] # iterate through the items for i, item in enumerate(statusSearchResults): tempItem = sqlitedb.getItemById(item) # obtain the item # 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' # obtain categories for the item tempItem['Categories'] = sqlitedb.getCategory(item) # add the href value to the item page tempItem['href'] = '/show_item/' + str(item) final_items.append(tempItem) return render_template('search.html', search_result=final_items)