def vote(postVars):
	
	global couchdbServer
	
	templateVars = dict()
	winnerId = postVars["winner"].value.decode("utf-8")
	loserId = postVars["loser"].value.decode("utf-8")
	
	try:
		db = couchdbServer.create("players")
	except:
		db = couchdbServer["players"]
	
	winner = Player.load(db,winnerId)
	loser = Player.load(db,loserId)

	match = Match()
	if postVars["draw"].value == "0":
		match.matchWithWinner(winner,loser)
	else:
		match.matchWithoutWinner(winner,loser)
	
	try:
		winner.store(db)
	except ResourceConflict:
		print "Unable to store winner"
	
	try:
		loser.store(db)
	except ResourceConflict:
		print "Unable to store loser"
		
		
	votesCount = classes.rankingsession.getSession("votesToFinish")
	votesCount -= 1
	votesCount = classes.rankingsession.setSession("votesToFinish", votesCount)
	
	templateVars = dict(json = json.dumps(dict()))
	return output_template("json.html", templateVars )
	def testMatchesResults(self):

		server = Server()
		try:
			db = server.create("players")
		except:
			db = server["players"]

		player0 = Player()
		player0.store(db)
		player1 = Player()
		player1.store(db)
		
		match = Match()

		match.matchWithWinner(player0, player1)
		self.assertEqual(player0.karma, 405), "Error on match"
		self.assertEqual(player0.matches, 1), "Error on match"
		self.assertEqual(player0.wins, 1), "Error on match"
		self.assertEqual(player0.losses, 0), "Error on match"
		self.assertEqual(player1.karma, 395), "Error on match"
		self.assertEqual(player1.matches, 1), "Error on match"
		self.assertEqual(player1.wins, 0), "Error on match"
		self.assertEqual(player1.losses, 1), "Error on match"
		
		match.matchWithWinner(player1, player0)
		self.assertEqual(player0.karma, 400), "Error on match"
		self.assertEqual(player0.matches, 2), "Error on match"
		self.assertEqual(player0.wins, 1), "Error on match"
		self.assertEqual(player0.losses, 1), "Error on match"
		self.assertEqual(player1.karma, 400), "Error on match"
		self.assertEqual(player1.matches, 2), "Error on match"
		self.assertEqual(player1.wins, 1), "Error on match"
		self.assertEqual(player1.losses, 1), "Error on match"

		match.matchWithWinner(player0, player1)
		self.assertEqual(player0.karma, 405), "Error on match"
		self.assertEqual(player0.matches, 3), "Error on match"
		self.assertEqual(player1.karma, 395), "Error on match"
		self.assertEqual(player1.matches, 3), "Error on match"

		match.matchWithWinner(player0,player1)
		self.assertEqual(player0.karma, 410), "Error on match"
		self.assertEqual(player0.matches, 4), "Error on match"
		self.assertEqual(player1.karma, 390), "Error on match"
		self.assertEqual(player1.matches, 4), "Error on match"

		match.matchWithWinner(player0, player1)
		self.assertEqual(player0.karma, 415), "Error on match"
		self.assertEqual(player0.matches, 5), "Error on match"
		self.assertEqual(player1.karma, 385), "Error on match"
		self.assertEqual(player1.matches, 5), "Error on match"

		match.matchWithWinner(player0, player1)
		self.assertEqual(player0.karma, 419.7), "Error on match"
		self.assertEqual(player0.matches, 6), "Error on match"
		self.assertEqual(player1.karma, 380.3), "Error on match"
		self.assertEqual(player1.matches, 6), "Error on match"

		player0.resetKarma()
		player1.resetKarma()
		match.matchWithoutWinner(player0, player1)
		self.assertEqual(player0.karma, 400), "Error on match"
		self.assertEqual(player0.matches, 1), "Error on match"
		self.assertEqual(player1.karma, 400), "Error on match"
		self.assertEqual(player1.matches, 1), "Error on match"
		self.assertEqual(player1.wins, 0), "Error on match"
		self.assertEqual(player1.losses, 0), "Error on match"

		match.matchWithWinner(player0, player1)
		self.assertEqual(player0.karma, 405), "Error on match"
		self.assertEqual(player0.matches, 2), "Error on match"
		self.assertEqual(player1.karma, 395), "Error on match"
		self.assertEqual(player1.matches, 2), "Error on match"
		
		match.matchWithoutWinner(player0, player1)
		self.assertEqual(player0.karma, 405), "Error on match"
		self.assertEqual(player0.matches, 3), "Error on match"
		self.assertEqual(player1.karma, 395), "Error on match"
		self.assertEqual(player1.matches, 3), "Error on match"

		match.matchWithoutWinner(player0, player1)
		self.assertEqual(player0.karma, 405), "Error on match"
		self.assertEqual(player0.matches, 4), "Error on match"
		self.assertEqual(player1.karma, 395), "Error on match"
		self.assertEqual(player1.matches, 4), "Error on match"