def games(request): if request.method == "POST": Game.createFor(request.user, request.POST.get('playAs', 'X')) return redirect(reverse(games)) else: return render_csrf('games.html', request, { 'activeGames': Game.findActiveFor(request.user), 'pendingGames': Game.findPendingFor(request.user), 'finishedGames': Game.findFinishedFor(request.user) })
def join(request, gameId): # this is the nice restful interface if Game.tryToJoin(request.user, gameId): # @TODO: go directly to game if we're playing as X return redirect(reverse(games)) else: return redirect(reverse(joinable))
def joinable(request): # this is just a convienience for the pure HTML interface # @TODO: see if any browsers actually support url templates for forms if request.method == "POST": gameId = int(request.POST['gameId']) return join(request, gameId) else: return render_csrf('joinable.html', request, { 'joinable': Game.findJoinableBy(request.user) })