def get(self, id): tourney = GetTourneyWithIdAndMaybeReturnStatus(self.response, id) if not tourney: return if not CheckUserOwnsTournamentAndMaybeReturnStatus( self.response, users.get_current_user(), tourney): return boards = ReadJSONInput(tourney.GetScoredHandList()) max_rounds = GetMaxRounds(boards) summaries = Calculate(boards, max_rounds) mp_summaries = summaries ap_summaries = summaries boards.sort(key=lambda bs: bs._board_no, reverse=False) wb = WriteResultsToXlsx(max_rounds, mp_summaries, ap_summaries, boards, name_list=GetPlayerListForTourney(tourney)) self.response.out.write(OutputWorkbookAsBytesIO(wb).getvalue()) self.response.headers[ 'Content-Type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' self.response.headers['Content-disposition'] = str( 'attachment; filename=' + tourney.name + 'TournamentResults.xlsx') self.response.headers['Content-Transfer-Encoding'] = 'Binary' self.response.set_status(200)
def put(self, id): user = users.get_current_user() tourney = GetTourneyWithIdAndMaybeReturnStatus(self.response, id) if not tourney: return if not CheckUserOwnsTournamentAndMaybeReturnStatus( self.response, user, tourney): return request_dict = self._ParseRequestInfoAndMaybeSetStatus() if not request_dict: return name = request_dict['name'] no_pairs = request_dict['no_pairs'] no_boards = request_dict['no_boards'] player_list = request_dict.get('players') if not self._CheckValidTournamentInfoAndMaybeSetStatus( name, no_pairs, no_boards, player_list): return if ((tourney.no_pairs != no_pairs or tourney.no_boards != no_boards) and len(tourney.GetScoredHandList()) != 0): SetErrorStatus(self.response, 400, "Invalid Request", "Tournament already has registered hands") return self.response.set_status(204) tourney.no_pairs = no_pairs tourney.no_boards = no_boards tourney.name = name tourney_key = tourney.put() tourney.PutPlayers(player_list, no_pairs)
def get(self, id): ''' Returns tournament metadata for tournament with id. Args: id: tournament ID to look up. Tournament must already have been created. ''' user = users.get_current_user() tourney = GetTourneyWithIdAndMaybeReturnStatus(self.response, id) if not tourney: return if not CheckUserOwnsTournamentAndMaybeReturnStatus( self.response, user, tourney): return combined_dict = { 'no_pairs': tourney.no_pairs, 'no_boards': tourney.no_boards, 'name': tourney.name, 'hands': tourney.GetScoredHandList() } player_pairs = PlayerPair.query(ancestor=tourney.key).fetch() player_pairs.sort(key=lambda p: p.pair_no) combined_dict['pair_ids'] = [p.id for p in player_pairs] for player_pair in player_pairs: if player_pair.players: for player in player_pair.player_list(): player['pair_no'] = player_pair.pair_no combined_dict.setdefault('players', []).append(player) self.response.headers['Content-Type'] = 'application/json' self.response.set_status(200) self.response.out.write(json.dumps(combined_dict, indent=2))
def get(self, id): ''' Returns tournament metadata for tournament with id. Args: id: tournament ID to look up. Tournament must already have been created. ''' user = users.get_current_user() tourney = GetTourneyWithIdAndMaybeReturnStatus(self.response, id) if not tourney: return if not CheckUserOwnsTournamentAndMaybeReturnStatus(self.response, user, tourney): return combined_dict = {'no_pairs' : tourney.no_pairs, 'no_boards' :tourney.no_boards, 'name' : tourney.name, 'allow_score_overwrites' : tourney.IsUnlocked(), 'hands' : tourney.GetScoredHandList()} player_futures = tourney.GetAllPlayerPairsAsync(); for player_pair in player_futures: pp = player_pair.get_result() if pp.players: for player in pp.player_list(): player['pair_no'] = pp.pair_no combined_dict.setdefault('players', []).append(player) combined_dict['pair_ids'] = [p.get_result().id for p in player_futures] self.response.headers['Content-Type'] = 'application/json' self.response.set_status(200) self.response.out.write(json.dumps(combined_dict, indent=2))
def get(self, id): tourney = GetTourneyWithIdAndMaybeReturnStatus(self.response, id) if not tourney: return if not CheckUserOwnsTournamentAndMaybeReturnStatus( self.response, users.get_current_user(), tourney): return hand_list = tourney.GetScoredHandList() boards = ReadJSONInput(hand_list) summaries = Calculate(boards, GetMaxRounds(boards)) self.response.headers['Content-Type'] = 'application/json' self.response.set_status(200) self.response.out.write(OutputJSON(hand_list, summaries))
def put(self, id): user = users.get_current_user() tourney = GetTourneyWithIdAndMaybeReturnStatus(self.response, id) if not tourney: return if not CheckUserOwnsTournamentAndMaybeReturnStatus(self.response, user, tourney): return request_dict = self._ParseRequestInfoAndMaybeSetStatus() if not request_dict: return name = request_dict['name'] no_pairs = request_dict['no_pairs'] no_boards = request_dict['no_boards'] player_list = request_dict.get('players') allow_score_overwrites = request_dict.get('allow_score_overwrites', False) if not self._CheckValidTournamentInfoAndMaybeSetStatus(name, no_pairs, no_boards, player_list, tourney.legacy_version_id): return if ((tourney.no_pairs != no_pairs or tourney.no_boards != no_boards) and len(tourney.GetScoredHandList()) != 0): SetErrorStatus(self.response, 400, "Invalid Request", "Tournament already has registered hands") return old_no_pairs = tourney.no_pairs tourney.no_pairs = no_pairs tourney.no_boards = no_boards tourney.name = name if allow_score_overwrites: tourney.Unlock() else: tourney.MakeLockable() tourney.PutPlayers(player_list, old_no_pairs) tourney_key = tourney.put_async() self.response.set_status(204)