def addPlayer(postVars): global couchdbServer templateVars = dict(saved = False) try: templateVars["name"] = postVars["playerName"].value.decode("utf-8") templateVars["birth"] = postVars["playerBirth"].value.decode("utf-8") templateVars["nickname"] = postVars["playerNickname"].value.decode("utf-8") tempImagePath = "/tmp/%s" % postVars["playerPhoto"].filename tempImageFile = open(tempImagePath ,"w") tempImageFile.write(postVars["playerPhoto"].value) tempImageFile.close(); try: db = couchdbServer.create("players") except: db = couchdbServer["players"] player = Player() player.setName(templateVars["name"]) player.birth = templateVars["birth"] player.nickname = templateVars["nickname"] player.setPhoto(tempImagePath) player.store(db) templateVars["saved"] = True except KeyError: name = u"undef" return output_template("addPlayer.html", templateVars)