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:
parent
7b36398521
commit
92e41a5b92
3 changed files with 36 additions and 22 deletions
|
@ -23,7 +23,7 @@ def display_game_creation_form(req,sessionid,username):
|
||||||
<p>Goban Size: %s fields </p>
|
<p>Goban Size: %s fields </p>
|
||||||
<input type="hidden" name="sessionid" value="%s"><p>
|
<input type="hidden" name="sessionid" value="%s"><p>
|
||||||
<input type="hidden" name="username" 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>
|
</form>
|
||||||
""" % (p1data,p2data,gobansize,sessionid,username)
|
""" % (p1data,p2data,gobansize,sessionid,username)
|
||||||
|
|
||||||
|
@ -32,15 +32,18 @@ def display_game_creation_form(req,sessionid,username):
|
||||||
data+=helper.footer()
|
data+=helper.footer()
|
||||||
req.write(data)
|
req.write(data)
|
||||||
|
|
||||||
def process_creation_form(req):
|
def process_creation_form(req,form):
|
||||||
"""
|
"""
|
||||||
validates and processes the game creation form.
|
validates and processes the game creation form.
|
||||||
If everything was ok, a game will be created.
|
If everything was ok, a game will be created.
|
||||||
"""
|
"""
|
||||||
#check if at least one of the players is the current user
|
#check if at least one of the players is the current user
|
||||||
|
if (form["playerone"] == form["username"]) or (form["playertwo"] == form["username"]):
|
||||||
#create game name
|
#create game name
|
||||||
#create_game
|
#create_game
|
||||||
#update entries for player one and player two
|
#update entries for player one and player two
|
||||||
|
else:
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def create_user_dropdown_list(listname,selected = ""):
|
def create_user_dropdown_list(listname,selected = ""):
|
||||||
|
@ -79,12 +82,14 @@ def main(req,form):
|
||||||
gets a request object and a util.FieldStorage form.
|
gets a request object and a util.FieldStorage form.
|
||||||
returns nothing.
|
returns nothing.
|
||||||
"""
|
"""
|
||||||
|
req.write(str(form.keys())+"<hr>")
|
||||||
|
|
||||||
username = form["username"]
|
username = form["username"]
|
||||||
#TODO:check if valid session id
|
#TODO:check if valid session id
|
||||||
sessionid = form["sessionid"]
|
sessionid = form["sessionid"]
|
||||||
if "create" in form.keys(): #first call of this function
|
if "gobansize" in form.keys(): #user already clicked on create
|
||||||
display_game_creation_form(req,sessionid,username)
|
process_creation_form(req,form)
|
||||||
else:
|
else:
|
||||||
process_creation_form(req)
|
display_game_creation_form(req,sessionid,username)
|
||||||
form = util.FieldStorage(req)
|
form = util.FieldStorage(req)
|
||||||
req.write(str(form))
|
req.write(str(form))
|
16
login.py
16
login.py
|
@ -4,7 +4,7 @@ from mod_python import *
|
||||||
|
|
||||||
def process_form(req,form):
|
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):
|
#if form == empty (which means if page is displayed for the first time):
|
||||||
req.write(str(form.keys()))
|
req.write(str(form.keys()))
|
||||||
|
@ -69,11 +69,10 @@ def game_overview_form(req,user,sessionid):
|
||||||
if counter > 0:
|
if counter > 0:
|
||||||
data+= "You have %s free game slots.<br>" % counter
|
data+= "You have %s free game slots.<br>" % counter
|
||||||
data += """
|
data += """
|
||||||
<form>
|
<form method="post">
|
||||||
<input type=submit name="create" value="Start a new game">
|
|
||||||
<input type="hidden" name="sessionid" value="%s">
|
<input type="hidden" name="sessionid" value="%s">
|
||||||
<input type="hidden" name="username" value="%s">
|
<input type="hidden" name="username" value="%s">
|
||||||
|
<input type=submit name="create" value="Start a new game">
|
||||||
</form>
|
</form>
|
||||||
""" % (sessionid, user)
|
""" % (sessionid, user)
|
||||||
else:
|
else:
|
||||||
|
@ -111,13 +110,14 @@ def login_form():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main(req):
|
def main(req,form):
|
||||||
#get instance of fieldstorage
|
|
||||||
form = util.FieldStorage(req)
|
|
||||||
if "sessionid" not in form.keys():
|
if "sessionid" not in form.keys():
|
||||||
req.write(login_form())
|
req.write(login_form())
|
||||||
elif ("create" in form.keys()) and ("username" in form.keys()):
|
elif ("create" in form.keys()) and ("username" in form.keys()):
|
||||||
#user wants to create a new game
|
#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:
|
else:
|
||||||
process_form(req,form)
|
process_form(req,form)
|
||||||
|
|
17
main.py
17
main.py
|
@ -5,7 +5,7 @@ taken from http://gnosis.cx/publish/programming/feature_5min_python.html
|
||||||
modified a little
|
modified a little
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from mod_python import apache
|
from mod_python import *
|
||||||
|
|
||||||
import sys, traceback
|
import sys, traceback
|
||||||
import init_webgo
|
import init_webgo
|
||||||
|
@ -15,14 +15,23 @@ DEBUG = 1
|
||||||
|
|
||||||
def handler(req):
|
def handler(req):
|
||||||
# "Content-type: text/html\n\n"
|
# "Content-type: text/html\n\n"
|
||||||
req.content_type = "text/html"
|
req.content_type = "text/html"#was:text/html
|
||||||
try: # use explicit exception handling
|
try: # use explicit exception handling
|
||||||
#reinitialize database
|
#reinitialize database
|
||||||
#init_webgo.main()
|
#init_webgo.main()
|
||||||
|
|
||||||
login = apache.import_module("login")
|
#load form, then delegate request
|
||||||
login.main(req)
|
form = util.FieldStorage(req)
|
||||||
|
if "create" in form.keys():
|
||||||
|
gamecreation = apache.import_module("gamecreation")
|
||||||
|
gamecreation.main(req,form)
|
||||||
return apache.OK
|
return apache.OK
|
||||||
|
else:
|
||||||
|
#call login.py
|
||||||
|
login = apache.import_module("login")
|
||||||
|
login.main(req,form)
|
||||||
|
return apache.OK
|
||||||
|
|
||||||
except:
|
except:
|
||||||
import time
|
import time
|
||||||
errtime = '----- '+ time.ctime(time.time()) +' -----\n'
|
errtime = '----- '+ time.ctime(time.time()) +' -----\n'
|
||||||
|
|
Loading…
Reference in a new issue