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
DEBUG = 1
def delete_game(gamename,username):
"""
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
delete game from database.
"""
if DEBUG:
req.write(str(form.keys())+" sessionid in form:"+form["sessionid"]+"<hr>")
helper.debug(req,form,str(form.keys())+" sessionid in form:"+form["sessionid"]+"<hr>")
try:
gamename = form["game"]
except:
@ -44,7 +41,7 @@ def main(req,form):
#delete table
psql.drop_table(gamename)
#now display game overview form.
login.game_overview_form(req,form,player,form["sessionid"])
login.game_overview_form(req,form)
else:
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_game_creation_form(req,form["sessionid"],username)
#TODO:game created, now display game overview form
login.game_overview_form(req,form,username,form["sessionid"])
login.game_overview_form(req,form)
else:
#give error message
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>")
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
name = form["name"]
username = form["username"]
password = form["password"]
sessionid = form["sessionid"]
origpassword = psql.get_user_info(name,"password")
origpassword = psql.get_user_info(username,"password")
#debug:
helper.debug(req,form,'<hr>--password:'+str(password)+' ---origpassword:'+str(origpassword)+'<hr>')
#check if user exists (else we would get an error string)
if origpassword != "no such user": #no error message, now check password
if password == origpassword:
#login accepted
psql.set_user_sessionid(name,sessionid)
psql.set_user_timeout(name)
psql.set_user_sessionid(username,sessionid)
psql.set_user_timeout(username)
#now display list of games.
game_overview_form(req,form,name,sessionid)
game_overview_form(req,form)
else:
req.write("Login incorrect. Please try again.<br>")
req.write(login_form())
@ -34,16 +34,19 @@ def process_form(req,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.
prints a form with the option to select,create and delete games.
"""
username = form["username"]
sessionid = form["sessionid"]
data = helper.header()+ """
<h2> Current Games: </h2>
<form method="post">
"""
gamelist = psql.get_user_game_list(user)
gamelist = psql.get_user_game_list(username)
#debug
helper.debug(req,form,str(gamelist)+"<hr>\n")
#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"
else:
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 += '<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.
@ -72,7 +75,7 @@ def game_overview_form(req,form,user,sessionid):
<input type="hidden" name="username" value="%s">
<input type=submit id="submit" name="create" value="Start a new game">
</form>
""" % (sessionid, user)
""" % (sessionid, username)
else:
data+= "Sorry, all your game slots are in use."
#display "You have ... free game slots" + Button "create game"
@ -88,7 +91,7 @@ def login_form():
data = helper.header() + """
<form method="post">
<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>
<input name="password" type="text" id="text" size="20"></p>
<input type="hidden" name="sessionid" value="%s">
@ -109,8 +112,8 @@ def navigation_bar(username,sessionid):
#TODO: buttons
data="""
<form method="post">
<input type="hidden" name="sessionid" 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="game overview" value="game overview">
</form>
@ -130,6 +133,6 @@ def main(req,form):
elif ("create" in form.keys()) and ("username" in form.keys()):
pass
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:
process_form(req,form)