Added doc string to main.py
parent
f402ae36af
commit
e504aa48c6
4
main.py
4
main.py
|
@ -7,10 +7,12 @@ TEMPLATE = "template.html"
|
||||||
games = dict()
|
games = dict()
|
||||||
|
|
||||||
def is_submitted(name):
|
def is_submitted(name):
|
||||||
|
"""Return True if form element with name was submitted."""
|
||||||
return request.forms.get(name) != None
|
return request.forms.get(name) != None
|
||||||
|
|
||||||
@get("/")
|
@get("/")
|
||||||
def index():
|
def index():
|
||||||
|
"""Drop cookie if it doesn't exist. Redirect to /game/."""
|
||||||
if request.get_cookie("gameid", secret=KEY) not in games.keys():
|
if request.get_cookie("gameid", secret=KEY) not in games.keys():
|
||||||
game = Game()
|
game = Game()
|
||||||
id = str(max(list(map(int, games.keys()))+[0]) + 1)
|
id = str(max(list(map(int, games.keys()))+[0]) + 1)
|
||||||
|
@ -20,6 +22,7 @@ def index():
|
||||||
|
|
||||||
@get("/game/")
|
@get("/game/")
|
||||||
def show():
|
def show():
|
||||||
|
"""Show board. Redirect to index if id given by cookie not in games."""
|
||||||
id = request.get_cookie("gameid", secret=KEY)
|
id = request.get_cookie("gameid", secret=KEY)
|
||||||
if id not in games:
|
if id not in games:
|
||||||
redirect("/")
|
redirect("/")
|
||||||
|
@ -27,6 +30,7 @@ def show():
|
||||||
|
|
||||||
@post("/game/")
|
@post("/game/")
|
||||||
def move():
|
def move():
|
||||||
|
"""Catch form submissions and manipulate the game instance."""
|
||||||
id = request.get_cookie("gameid", secret=KEY)
|
id = request.get_cookie("gameid", secret=KEY)
|
||||||
valid = True
|
valid = True
|
||||||
if is_submitted("newgame"):
|
if is_submitted("newgame"):
|
||||||
|
|
Loading…
Reference in New Issue