diff --git a/main.py b/main.py index 0faf211..518c3c8 100644 --- a/main.py +++ b/main.py @@ -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"):