def post(self): user = users.get_current_user() if not CheckUserLoggedInAndMaybeReturnStatus(self.response, user): 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 tourney = Tournament.CreateAndPersist( owner_id=user.user_id(), name=name, no_pairs=no_pairs, no_boards=no_boards, boards=boardgenerator.GenerateBoards(35)) tourney.PutPlayers(player_list, no_pairs) self.response.set_status(201) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({"id": str(tourney.key.id())}))
def post(self): user = users.get_current_user() request_dict = self._ValidateNewTournamentInfoAndMaybeSetStatus(user) 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) tourney = Tournament.CreateAndPersist(owner_id=user.user_id(), name=name, no_pairs=no_pairs, no_boards=no_boards, boards=boardgenerator.GenerateBoards(35)) tourney.PutPlayers(player_list, 0) if allow_score_overwrites: tourney.Unlock() else: tourney.MakeLockable() self.response.set_status(201) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({"id": str(tourney.key.id())}))
def put(self): ''' Creates a new tournament with all the preexisting hands based on the the parameters specified in the request. ''' user = users.get_current_user() new_tournament_dict = self._ValidateNewTournamentInfoAndMaybeSetStatus(user) if not new_tournament_dict: return name = new_tournament_dict['name'] no_pairs = new_tournament_dict['no_pairs'] no_boards = new_tournament_dict['no_boards'] player_list = new_tournament_dict.get('players') allow_score_overwrites = new_tournament_dict.get('allow_score_overwrites', False) tourney = Tournament.CreateAndPersist(owner_id=user.user_id(), name = name, no_pairs=no_pairs, no_boards=no_boards, boards=boardgenerator.GenerateBoards(35)) tourney.PutPlayers(player_list, 0) if allow_score_overwrites: tourney.Unlock() else: tourney.MakeLockable() hands_list = self._ParseHandsFromRequestAndMaybeSetStatus() if hands_list is None: return for hand in hands_list: board_no = hand.get("board_no") ns_pair = hand.get("ns_pair") ew_pair = hand.get("ew_pair") if not CheckValidHandPlayersCombinationAndMaybeSetStatus( self.response, tourney, int(board_no), int(ns_pair), int(ew_pair)): return calls = hand.setdefault("calls", {}) ns_score = hand.get("ns_score") ew_score = hand.get("ew_score") notes = hand.get("notes") if not ValidateHandResultMaybeSetStatus(self.response, int(board_no), int(ns_pair), int(ew_pair), ns_score, ew_score, calls): return tourney.PutHandScore(int(board_no), int(ns_pair), int(ew_pair), calls, ns_score, ew_score, notes, 0) self.response.set_status(201) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps({"id": str(tourney.key.id())}))