Ejemplo n.º 1
0
  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, pair_no):
        ''' Fetch movement for tournament with id and team pair_no. 

    Args:
      id: String. Tournament id. 
      pair_no: Integer. Pair number for the team whose movement we're getting.

    See api for request and response documentation.
    '''
        tourney = GetTourneyWithIdAndMaybeReturnStatus(self.response, id)
        if not tourney:
            return

        if not self._CheckValidPairMaybeSetStatus(tourney, pair_no):
            return

        player_pair = PlayerPair.GetByPairNo(tourney, int(pair_no))
        if not player_pair:
            SetErrorStatus(self.response, 404, "Invalid Request",
                           "Player pair {} not in tournament".format(pair_no))
            return

        if not self._CheckUserAllowedToSeeMovementMaybeSetStatus(
                tourney, player_pair):
            return

        no_hands_per_round, no_rounds = Movement.NumBoardsPerRoundFromTotal(
            tourney.no_pairs, tourney.no_boards)
        try:
            movement = Movement.CreateMovement(
                tourney.no_pairs, no_hands_per_round, no_rounds,
                tourney.legacy_version_id).GetMovement(int(pair_no))
        except ValueError:
            SetErrorStatus(self.response, 500, "Corrupted Data",
                           "No valid movement for this tourney's config")
            return

        movement_list = self._GetMovementHandsAsync(tourney, movement,
                                                    int(pair_no))

        combined_dict = {
            'name': tourney.name,
            'players': player_pair.player_list(),
            'allow_score_overwrites': tourney.IsUnlocked(),
            'movement': movement_list
        }

        self.response.headers['Content-Type'] = 'application/json'
        self.response.set_status(200)
        self.response.out.write(json.dumps(combined_dict, indent=2))