class DisconnectedController(webapp.RequestHandler): def __init__(self): self.raceService = RaceService() def post(self): runner_key = self.request.get('from') runner = Runner.get(runner_key) race = runner.race self.raceService.sendDisconnectedToRunners(runner, race) runner.delete()
class RaceController(webapp.RequestHandler): def __init__(self): self.raceService = RaceService() def get(self, raceKey): if not users.get_current_user(): """ If users are not logged in redirect to a login page """ url = users.create_login_url(self.request.uri) self.redirect(url, False) return; race = Race.get(raceKey) my_runner = self.raceService.joinRace(users.get_current_user(), race) channel_token = channel.create_channel(str(my_runner.key())) template_values = { 'race_name': race.name, 'race_key': raceKey, 'race_description': race.description, 'race_status': race.status, 'runner_key': str(my_runner.key()), 'runner_ready' : "true" if my_runner.ready else "false", 'channel_token': channel_token, 'runners' : self.raceService.getRunnersAsModel(race) } logging.error(my_runner.ready); path = os.path.join(os.path.dirname(__file__), '../../templates/show-race.html') self.response.out.write(template.render(path, template_values)) self.raceService.sendUpdateToRunners(my_runner, race) def post(self): race = Race() if users.get_current_user(): race.admin = users.get_current_user() race.name = self.request.get('name') race.description = self.request.get('description') race.status = "lobby" race.put() self.redirect('/race/' + str(race.key()))
class RaceController(webapp.RequestHandler): def __init__(self): self.raceService = RaceService() def get(self, raceKey): if not users.get_current_user(): """ If users are not logged in redirect to a login page """ url = users.create_login_url(self.request.uri) self.redirect(url, False) return race = Race.get(raceKey) my_runner = self.raceService.joinRace(users.get_current_user(), race) channel_token = channel.create_channel(str(my_runner.key())) template_values = { 'race_name': race.name, 'race_key': raceKey, 'race_description': race.description, 'race_status': race.status, 'runner_key': str(my_runner.key()), 'runner_ready': "true" if my_runner.ready else "false", 'channel_token': channel_token, 'runners': self.raceService.getRunnersAsModel(race) } logging.error(my_runner.ready) path = os.path.join(os.path.dirname(__file__), '../../templates/show-race.html') self.response.out.write(template.render(path, template_values)) self.raceService.sendUpdateToRunners(my_runner, race) def post(self): race = Race() if users.get_current_user(): race.admin = users.get_current_user() race.name = self.request.get('name') race.description = self.request.get('description') race.status = "lobby" race.put() self.redirect('/race/' + str(race.key()))
class RacePodiumRequestHandler(webapp.RequestHandler): def __init__(self): self.raceService = RaceService() def get(self, raceKey): """ Render a html portion showing the race podium """ race = Race.get(raceKey) self.raceService.getRunnersAsModel(race) template_values = {'runners': self.raceService.getRunnersAsModel(race)} path = os.path.join(os.path.dirname(__file__), '../../templates/show-race-podium.html') self.response.out.write(template.render(path, template_values))
class RacePodiumRequestHandler(webapp.RequestHandler): def __init__(self): self.raceService = RaceService() def get(self, raceKey): """ Render a html portion showing the race podium """ race = Race.get(raceKey) self.raceService.getRunnersAsModel(race) template_values = { 'runners' : self.raceService.getRunnersAsModel(race) } path = os.path.join(os.path.dirname(__file__), '../../templates/show-race-podium.html') self.response.out.write(template.render(path, template_values))
class RunnerResource(webapp.RequestHandler): def __init__(self): self.raceService = RaceService() def post(self, runnerKey): jsonMessage = simplejson.loads(self.request.body); runner = Runner.get(runnerKey) {'gameUpdate': self.handleUpdate, 'runnerStatusUpdate': self.handleReady}[jsonMessage["messageType"]](runner, jsonMessage) def handleReady(self, runner, jsonMessage): status = jsonMessage["payload"][str(runner.key())] runner.ready = status; runner.put(); self.raceService.sendToRunners(runner.race, self.request.body) if (self.raceService.areAllRunnersReady(runner.race)): self.raceService.startRace(runner.race) def handleUpdate(self, runner, jsonMessage): winner = self.getWinner(jsonMessage); if (winner): race = runner.race race.status = "finished" # TODO status should be a constant of the model race.put() self.raceService.send_finish(race, winner) return runner.position = jsonMessage["payload"][str(runner.key())]; self.raceService.sendToRunners(runner.race, self.request.body) runner.put(); def getWinner(self, update): for runnerKey in update["payload"]: if (update["payload"][runnerKey] > 100) : return Runner.get(runnerKey).user.nickname()
def __init__(self): self.raceService = RaceService()