def takeSnapshot(postVars):
	
	global couchdbServer
	
	templateVars = dict(saved = False)

	try:
			db = couchdbServer.create("snapshots")
	except:
			db = couchdbServer["snapshots"]

	try:
		snapshotName = postVars["snapshotName"].value.decode("utf-8")	
		snapshot = Snapshot()
		snapshot.description = snapshotName
		snapshot.takeSnapshot()
		snapshot.store(db)
	except:
		pass

	
	templateVars['snapshots'] = []
	for snapshotId in db:
		templateVars['snapshots'].append(Snapshot.load(db,snapshotId))
	
	templateVars['snapshots'] = sorted(templateVars['snapshots'], reverse = True, key=lambda snapshot: snapshot["date"])
	
	return output_template("takeSnapshot.html", templateVars)
	def testSnapshots(self):

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

		bolivar = Player()
		bolivar.setName("Bolivar")
		bolivar.setPhoto("images/bolivar.jpg")
		bolivar.setKarma(288)
		bolivar.store(db)

		indio = Player()
		indio.setName("Indio")
		indio.setPhoto("images/indio.jpg")
		indio.setKarma(388)
		indio.store(db)

		ss = Snapshot()
		ss.description = "Teste de snapshot"
		self.assertEqual(ss.takeSnapshot(), True), "Error taking snapshot"

		try:
			server.delete("snapshots")
		except:
			pass

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

		ss.store(db)

		ss = Snapshot.load(db,ss.id)
		server.delete(ss.name)
		server.delete("snapshots")