Added doc string to main.py

master
Tibor Bizjak 2019-09-10 23:33:28 +02:00
parent f402ae36af
commit e504aa48c6
1 changed files with 4 additions and 0 deletions

View File

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