def get(self, hunt_id): hunt = get_hunt_by_id(hunt_id) if not hunt: self.redirect('/') return teams = list(Team.all().filter('hunt = ', hunt)) self.response.out.write(utils.render('templates/teams.html', { 'hunt': hunt, 'hunt_name': hunt.name, 'started': bool(hunt.started), 'teams': teams, 'teams_json': json.dumps([{ 'id': team.key().id(), 'name': team.name, 'phone': team.phone, } for team in teams]), }))
def get(self, hunt_id): hunt = get_hunt_by_id(hunt_id) if not hunt: self.redirect("/") return teams = list(Team.all().filter("hunt = ", hunt)) self.response.out.write( utils.render( "templates/teams.html", { "hunt": hunt, "hunt_name": hunt.name, "started": bool(hunt.started), "teams": teams, "teams_json": json.dumps( [{"id": team.key().id(), "name": team.name, "phone": team.phone} for team in teams] ), }, ) )
def post(self, hunt_id): hunt = get_hunt_by_id(hunt_id) if not hunt: self.redirect('/') return teams_list = parse_json_objs(self.request.get('teams-list'), ['name', 'phone']) if not teams_list: self.redirect('/') return if not all(PHONE_NUMBER_RE.match(team['phone']) for team in teams_list): self.redirect('/') return if hunt.started: # TODO update existing teams pass else: for team in Team.all().filter('hunt =', hunt): team.delete() for team_dict in teams_list: Team(hunt=hunt, name=team_dict['name'], phone=team_dict['phone']).put() self.redirect('/hunt/%s/teams' % hunt.key().id())
def post(self, hunt_id): hunt = get_hunt_by_id(hunt_id) if not hunt: self.redirect("/") return teams_list = parse_json_objs(self.request.get("teams-list"), ["name", "phone"]) if not teams_list: self.redirect("/") return if not all(PHONE_NUMBER_RE.match(team["phone"]) for team in teams_list): self.redirect("/") return if hunt.started: # TODO update existing teams pass else: for team in Team.all().filter("hunt =", hunt): team.delete() for team_dict in teams_list: hunt.add_team(team_dict["name"], team_dict["phone"]) self.redirect("/hunt/%s/teams" % hunt.key().id())