renamed some variables, cleaned up some argument requirements of game_overview_form(), the game_overview button for the game display now works

This commit is contained in:
phear 2005-09-20 09:16:13 +00:00
parent e6a7b4e648
commit 18405f247a
3 changed files with 19 additions and 19 deletions

View file

@ -1,7 +1,5 @@
import psql,login import psql,login
DEBUG = 1
def delete_game(gamename,username): def delete_game(gamename,username):
""" """
get name of game and name of user. get name of game and name of user.
@ -26,8 +24,7 @@ def main(req,form):
manage the removal of game from game slots of players and manage the removal of game from game slots of players and
delete game from database. delete game from database.
""" """
if DEBUG: helper.debug(req,form,str(form.keys())+" sessionid in form:"+form["sessionid"]+"<hr>")
req.write(str(form.keys())+" sessionid in form:"+form["sessionid"]+"<hr>")
try: try:
gamename = form["game"] gamename = form["game"]
except: except:
@ -44,7 +41,7 @@ def main(req,form):
#delete table #delete table
psql.drop_table(gamename) psql.drop_table(gamename)
#now display game overview form. #now display game overview form.
login.game_overview_form(req,form,player,form["sessionid"]) login.game_overview_form(req,form)
else: else:
req.write('Error: You have to select a game to delete it!') req.write('Error: You have to select a game to delete it!')

View file

@ -56,7 +56,7 @@ def process_creation_form(req,form):
#display form again #display form again
display_game_creation_form(req,form["sessionid"],username) display_game_creation_form(req,form["sessionid"],username)
#TODO:game created, now display game overview form #TODO:game created, now display game overview form
login.game_overview_form(req,form,username,form["sessionid"]) login.game_overview_form(req,form)
else: else:
#give error message #give error message
req.write("Sorry, you must be one of the players!<br>") req.write("Sorry, you must be one of the players!<br>")

View file

@ -7,22 +7,22 @@ def process_form(req,form):
""" """
#req.write("<br>"+"name="+form['name']+", password="+form['password']+"<hr>") #req.write("<br>"+"name="+form['name']+", password="+form['password']+"<hr>")
if form.keys() != []: if form.keys() != []:
if ("name" in form.keys()) and ("password" in form.keys()): if ("username" in form.keys()) and ("password" in form.keys()):
#extract name and password #extract name and password
name = form["name"] username = form["username"]
password = form["password"] password = form["password"]
sessionid = form["sessionid"] sessionid = form["sessionid"]
origpassword = psql.get_user_info(name,"password") origpassword = psql.get_user_info(username,"password")
#debug: #debug:
helper.debug(req,form,'<hr>--password:'+str(password)+' ---origpassword:'+str(origpassword)+'<hr>') helper.debug(req,form,'<hr>--password:'+str(password)+' ---origpassword:'+str(origpassword)+'<hr>')
#check if user exists (else we would get an error string) #check if user exists (else we would get an error string)
if origpassword != "no such user": #no error message, now check password if origpassword != "no such user": #no error message, now check password
if password == origpassword: if password == origpassword:
#login accepted #login accepted
psql.set_user_sessionid(name,sessionid) psql.set_user_sessionid(username,sessionid)
psql.set_user_timeout(name) psql.set_user_timeout(username)
#now display list of games. #now display list of games.
game_overview_form(req,form,name,sessionid) game_overview_form(req,form)
else: else:
req.write("Login incorrect. Please try again.<br>") req.write("Login incorrect. Please try again.<br>")
req.write(login_form()) req.write(login_form())
@ -34,16 +34,19 @@ def process_form(req,form):
req.write(login_form()) req.write(login_form())
def game_overview_form(req,form,user,sessionid): def game_overview_form(req,form):
""" """
gets: request object, util.FieldStorage form, name of user, sessionid. gets: request object, util.FieldStorage form, name of user, sessionid.
prints a form with the option to select,create and delete games. prints a form with the option to select,create and delete games.
""" """
username = form["username"]
sessionid = form["sessionid"]
data = helper.header()+ """ data = helper.header()+ """
<h2> Current Games: </h2> <h2> Current Games: </h2>
<form method="post"> <form method="post">
""" """
gamelist = psql.get_user_game_list(user) gamelist = psql.get_user_game_list(username)
#debug #debug
helper.debug(req,form,str(gamelist)+"<hr>\n") helper.debug(req,form,str(gamelist)+"<hr>\n")
#display list of current games #display list of current games
@ -59,7 +62,7 @@ def game_overview_form(req,form,user,sessionid):
data += "You don't have any running games.\n" data += "You don't have any running games.\n"
else: else:
tmp += '<input type="hidden" name="sessionid" value="%s">\n' % sessionid tmp += '<input type="hidden" name="sessionid" value="%s">\n' % sessionid
tmp += '<input type="hidden" name="username" value="%s">\n' % user tmp += '<input type="hidden" name="username" value="%s">\n' % username
data += tmp data += tmp
data += '<input type=submit id="submit" name="play" value="Play selected game">\n<input type=submit id="submit" name="delete" value="Delete selected game">\n</form>' data += '<input type=submit id="submit" name="play" value="Play selected game">\n<input type=submit id="submit" name="delete" value="Delete selected game">\n</form>'
#now comes the option for creating new games. #now comes the option for creating new games.
@ -72,7 +75,7 @@ def game_overview_form(req,form,user,sessionid):
<input type="hidden" name="username" value="%s"> <input type="hidden" name="username" value="%s">
<input type=submit id="submit" name="create" value="Start a new game"> <input type=submit id="submit" name="create" value="Start a new game">
</form> </form>
""" % (sessionid, user) """ % (sessionid, username)
else: else:
data+= "Sorry, all your game slots are in use." data+= "Sorry, all your game slots are in use."
#display "You have ... free game slots" + Button "create game" #display "You have ... free game slots" + Button "create game"
@ -88,7 +91,7 @@ def login_form():
data = helper.header() + """ data = helper.header() + """
<form method="post"> <form method="post">
<p>Name:<br> <p>Name:<br>
<input name="name" type="text" id="text" size="20"></p> <input name="username" type="text" id="text" size="20"></p>
<p>Pasword:<br> <p>Pasword:<br>
<input name="password" type="text" id="text" size="20"></p> <input name="password" type="text" id="text" size="20"></p>
<input type="hidden" name="sessionid" value="%s"> <input type="hidden" name="sessionid" value="%s">
@ -109,8 +112,8 @@ def navigation_bar(username,sessionid):
#TODO: buttons #TODO: buttons
data=""" data="""
<form method="post"> <form method="post">
<input type="hidden" name="sessionid" value="%s">
<input type="hidden" name="username" value="%s"> <input type="hidden" name="username" value="%s">
<input type="hidden" name="sessionid" value="%s">
<input type="submit" id="submit" name="logout" value="logout"> <input type="submit" id="submit" name="logout" value="logout">
<input type="submit" id="submit" name="game overview" value="game overview"> <input type="submit" id="submit" name="game overview" value="game overview">
</form> </form>
@ -130,6 +133,6 @@ def main(req,form):
elif ("create" in form.keys()) and ("username" in form.keys()): elif ("create" in form.keys()) and ("username" in form.keys()):
pass pass
elif ("game overview" in form.keys()) and ("username" in form.keys()) and ("sessionid" in form.keys()): elif ("game overview" in form.keys()) and ("username" in form.keys()) and ("sessionid" in form.keys()):
game_overview_form(req,form,form["username"],form["sessionid"]) game_overview_form(req,form)
else: else:
process_form(req,form) process_form(req,form)