async def set_qualifiers_results_spreadsheet(self, ctx, spreadsheet_id: str, *, sheet_name: str = ""): """Sets the qualifiers results spreadsheet.""" tournament = self.get_tournament(ctx.guild.id) bracket = tournament.current_bracket spreadsheet_id = spreadsheet_api.extract_spreadsheet_id(spreadsheet_id) qualifiers_results_spreadsheet = bracket._qualifiers_results_spreadsheet if not qualifiers_results_spreadsheet: qualifiers_results_spreadsheet = tosurnament_api.create_qualifiers_results_spreadsheet( tournament.id, bracket.id, QualifiersResultsSpreadsheet(spreadsheet_id=spreadsheet_id, sheet_name=sheet_name), ) else: qualifiers_results_spreadsheet.spreadsheet_id = spreadsheet_id if sheet_name: qualifiers_results_spreadsheet.sheet_name = sheet_name tosurnament_api.update_qualifiers_results_spreadsheet( tournament.id, bracket.id, qualifiers_results_spreadsheet) await self.send_reply(ctx, "success", qualifiers_results_spreadsheet.spreadsheet_id)
async def set_bracket_spreadsheet(self, ctx, spreadsheet_type, spreadsheet_id, sheet_name): """Puts the input spreadsheet into the corresponding bracket.""" tournament = self.get_tournament(ctx.guild.id) bracket = tournament.current_bracket spreadsheet_id = spreadsheet.extract_spreadsheet_id(spreadsheet_id) if getattr(bracket, spreadsheet_type + "_spreadsheet_id") > 0: if spreadsheet_type == "players": any_spreadsheet = bracket.players_spreadsheet elif spreadsheet_type == "schedules": any_spreadsheet = bracket.schedules_spreadsheet else: return else: if spreadsheet_type == "players": any_spreadsheet = PlayersSpreadsheet() elif spreadsheet_type == "schedules": any_spreadsheet = SchedulesSpreadsheet() else: return self.bot.session.add(any_spreadsheet) setattr(bracket, spreadsheet_type + "_spreadsheet_id", any_spreadsheet.id) self.bot.session.update(bracket) any_spreadsheet.spreadsheet_id = spreadsheet_id if sheet_name: any_spreadsheet.sheet_name = sheet_name self.bot.session.update(any_spreadsheet) await self.send_reply(ctx, ctx.command.name, "success", spreadsheet_id)
async def set_bracket_spreadsheet(self, ctx, spreadsheet_type, spreadsheet_id, sheet_name): """Puts the input spreadsheet into the corresponding bracket.""" tournament = self.get_tournament(ctx.guild.id) bracket = tournament.current_bracket spreadsheet_id = spreadsheet.extract_spreadsheet_id(spreadsheet_id) any_spreadsheet = bracket.get_spreadsheet_from_type(spreadsheet_type) if not any_spreadsheet: any_spreadsheet = bracket.create_spreadsheet_from_type(self.bot, spreadsheet_type) any_spreadsheet.spreadsheet_id = spreadsheet_id if sheet_name: any_spreadsheet.sheet_name = sheet_name self.bot.session.update(any_spreadsheet) await self.send_reply(ctx, ctx.command.name, "success", spreadsheet_id)
def put(self, tournament_id, bracket_id, spreadsheet_id): spreadsheet = self._get_object(tournament_id, bracket_id, spreadsheet_id) body = request.json if "spreadsheet_id" in body: body["spreadsheet_id"] = spreadsheet_api.extract_spreadsheet_id( body["spreadsheet_id"]) spreadsheet.update(**body) db.update(spreadsheet) current_app.logger.debug( "The qualifiers spreadsheet {0} has been updated successfully.". format(spreadsheet_id)) return {}, 204
def post(self, tournament_id, bracket_id): bracket = (db.query(Bracket).where( Bracket.tournament_id == tournament_id).where( Bracket.id == bracket_id).first()) if not bracket: raise exceptions.NotFound() body = request.json if not body or not body["spreadsheet_id"]: raise exceptions.MissingRequiredInformation() body["spreadsheet_id"] = spreadsheet_api.extract_spreadsheet_id( body["spreadsheet_id"]) spreadsheet = QualifiersSpreadsheet(**body) db.add(spreadsheet) bracket.qualifiers_spreadsheet_id = spreadsheet.id db.update(bracket) current_app.logger.debug( "The qualifiers spreadsheet {0} for the bracket {1} has been created successfully." .format(spreadsheet.id, bracket_id)) return spreadsheet.get_api_dict(), 201
async def set_schedules_spreadsheet(self, ctx, spreadsheet_id: str, *, sheet_name: str = ""): """Sets the schedules spreadsheet.""" tournament = self.get_tournament(ctx.guild.id) bracket = tournament.current_bracket spreadsheet_id = spreadsheet_api.extract_spreadsheet_id(spreadsheet_id) schedules_spreadsheet = bracket._schedules_spreadsheet if not schedules_spreadsheet: schedules_spreadsheet = tosurnament_api.create_schedules_spreadsheet( tournament.id, bracket.id, SchedulesSpreadsheet(spreadsheet_id=spreadsheet_id, sheet_name=sheet_name)) else: schedules_spreadsheet.spreadsheet_id = spreadsheet_id if sheet_name: schedules_spreadsheet.sheet_name = sheet_name tosurnament_api.update_schedules_spreadsheet( tournament.id, bracket.id, schedules_spreadsheet) await self.send_reply(ctx, "success", schedules_spreadsheet.spreadsheet_id)