forms now work up to the point where a new game is to be created. the function for checking user input is still empty.

This commit is contained in:
phear 2005-09-12 11:28:11 +00:00
parent 7b36398521
commit 92e41a5b92
3 changed files with 36 additions and 22 deletions

View file

@ -23,7 +23,7 @@ def display_game_creation_form(req,sessionid,username):
<p>Goban Size: %s fields </p>
<input type="hidden" name="sessionid" value="%s"><p>
<input type="hidden" name="username" value="%s"><p>
<input type="submit" value="create game"></p>
<input type="submit" name="create" value="create game"></p>
</form>
""" % (p1data,p2data,gobansize,sessionid,username)
@ -32,15 +32,18 @@ def display_game_creation_form(req,sessionid,username):
data+=helper.footer()
req.write(data)
def process_creation_form(req):
def process_creation_form(req,form):
"""
validates and processes the game creation form.
If everything was ok, a game will be created.
"""
#check if at least one of the players is the current user
#create game name
#create_game
#update entries for player one and player two
if (form["playerone"] == form["username"]) or (form["playertwo"] == form["username"]):
#create game name
#create_game
#update entries for player one and player two
else:
pass
def create_user_dropdown_list(listname,selected = ""):
@ -79,12 +82,14 @@ def main(req,form):
gets a request object and a util.FieldStorage form.
returns nothing.
"""
req.write(str(form.keys())+"<hr>")
username = form["username"]
#TODO:check if valid session id
sessionid = form["sessionid"]
if "create" in form.keys(): #first call of this function
display_game_creation_form(req,sessionid,username)
if "gobansize" in form.keys(): #user already clicked on create
process_creation_form(req,form)
else:
process_creation_form(req)
display_game_creation_form(req,sessionid,username)
form = util.FieldStorage(req)
req.write(str(form))

View file

@ -4,7 +4,7 @@ from mod_python import *
def process_form(req,form):
"""
reads username and passsword from form
reads username and password from form
"""
#if form == empty (which means if page is displayed for the first time):
req.write(str(form.keys()))
@ -69,11 +69,10 @@ def game_overview_form(req,user,sessionid):
if counter > 0:
data+= "You have %s free game slots.<br>" % counter
data += """
<form>
<input type=submit name="create" value="Start a new game">
<form method="post">
<input type="hidden" name="sessionid" value="%s">
<input type="hidden" name="username" value="%s">
<input type=submit name="create" value="Start a new game">
</form>
""" % (sessionid, user)
else:
@ -111,13 +110,14 @@ def login_form():
def main(req):
#get instance of fieldstorage
form = util.FieldStorage(req)
def main(req,form):
if "sessionid" not in form.keys():
req.write(login_form())
elif ("create" in form.keys()) and ("username" in form.keys()):
#user wants to create a new game
gamecreation.main(req,form)
#gamecreation = apache.import_module("gamecreation")
#gamecreation.main(req,form)
#gamecreation.main(req,form)
pass
else:
process_form(req,form)

21
main.py
View file

@ -5,7 +5,7 @@ taken from http://gnosis.cx/publish/programming/feature_5min_python.html
modified a little
"""
from mod_python import apache
from mod_python import *
import sys, traceback
import init_webgo
@ -15,14 +15,23 @@ DEBUG = 1
def handler(req):
# "Content-type: text/html\n\n"
req.content_type = "text/html"
req.content_type = "text/html"#was:text/html
try: # use explicit exception handling
#reinitialize database
#init_webgo.main()
login = apache.import_module("login")
login.main(req)
return apache.OK
#load form, then delegate request
form = util.FieldStorage(req)
if "create" in form.keys():
gamecreation = apache.import_module("gamecreation")
gamecreation.main(req,form)
return apache.OK
else:
#call login.py
login = apache.import_module("login")
login.main(req,form)
return apache.OK
except:
import time
errtime = '----- '+ time.ctime(time.time()) +' -----\n'