コード例 #1
0
	def POST(self):
		post_params = web.input()
		itemID = post_params['itemID']
		userID = post_params['userID']
		price = post_params['price']
		update_message = 'Congradulations %s! You successfully made a bid for item %s for $%s' % (userID, itemID, price)

		t = sqlitedb.transaction()
		try:
			makeBidResult = sqlitedb.bid(itemID, userID, price)
		except Exception as e:
			t.rollback()
			update_message = str(e)
			if update_message == 'foreign key constraint failed':
				update_message = 'The username you entered cannot be recognized by our system. Please try again with a different username.'
			elif update_message == 'columns AuctionID, Time are not unique':
				update_message = 'You cannot make a bid at the same time. Please try again later.'
			elif update_message == 'The Bid Amount is not larger than the previous Amount!':
				update_message = 'You have to bid more than the last bid. Please try again with a higher amount.'
		else:
			t.commit()

		auctionResult = sqlitedb.getAuctionDetail(itemID)
		categoryResult = sqlitedb.getItemCategory(itemID)
		categoryString = ''
		for cr in categoryResult:
			categoryString += cr['Category']
			categoryString += ', '
		categoryString = categoryString[:len(categoryString)-2]
		bidResult = sqlitedb.getAuctionBids(itemID)
		winnerString = 'None'
		if bidResult:
			winnerString = bidResult[0]['BidderID']

		return render_template('item.html', items = auctionResult, categories = categoryString, bids = bidResult, winner = winnerString, message = update_message)
コード例 #2
0
	def GET(self):
		try:
			data = web.input()
			itemID = int(data.itemID)
		except Exception as e:
			return render_template('item.html')
		else:
			auctionResult = sqlitedb.getAuctionDetail(itemID)
			categoryResult = sqlitedb.getItemCategory(itemID)
			categoryString = ''
			for cr in categoryResult:
				categoryString += cr['Category']
				categoryString += ', '
			categoryString = categoryString[:len(categoryString)-2]
			bidResult = sqlitedb.getAuctionBids(itemID)
			winnerString = 'None'
			if bidResult:
				winnerString = bidResult[0]['BidderID']

			return render_template('item.html', items = auctionResult, categories = categoryString, bids = bidResult, winner = winnerString)