def on_put(self, request, response, id, dateId, pitchId, gameId): print('Updating Game: ' + id + '/' + dateId + '/' + pitchId + '/' + gameId) body = json.loads(request.stream.read()) if 'eventLog' in body: print('Has eventLog') else: print('Does not have eventLog') connection = tourneyDatabase.tourneyDatabase() try: email = googleAuthentication.getAuthenticatedEmail(request.headers) print('Email: ' + str(email)) (tournament, gameDate, pitch, game) = Game.getGame(response, connection, id, dateId, pitchId, gameId) # pylint: disable=unused-variable if game: # and tournament.canEdit(email): print('Found Game') for attempt in transaction.manager.attempts(): with attempt: game.assign(body) transaction.commit() print('Game updated') else: print('Game Not Found') finally: connection.close()
def on_put(self, request, response, id, dateId, pitchId, gameId, version): print('Restoring Game History: ' + id + '/' + dateId + '/' + pitchId + '/' + gameId) connection = tourneyDatabase.tourneyDatabase() try: email = googleAuthentication.getAuthenticatedEmail(request.headers) print('Email: ' + str(email)) (tournament, gameDate, pitch, game) = Game.getGame(response, connection, id, dateId, pitchId, gameId) # pylint: disable=unused-variable if game: # and tournament.canEdit(email): game.ensureLoadedEventLog() history_game = game.get_game_history(version) json.dumps(history_game) # force data to load history_events = history_game['game']['eventLog'] for attempt in transaction.manager.attempts(): with attempt: game.clearEventLog(False) for event in history_events: eventItem = game.addLogEvent( event.time, event.eventType, event.team, event.player, event.notes) eventItem.teamOriginal = event.teamOriginal transaction.commit() print('Game Revision Restored') #response.text = 'OK' finally: connection.close()
def on_put(self, request, response, id): connection = tourneyDatabase.tourneyDatabase() try: tournament = connection.tournaments.getByShortId(id) if tournament: tournament.addDate() finally: connection.close()
def on_delete(self, request, response, id, dateId): connection = tourneyDatabase.tourneyDatabase() try: (tournament, date) = GameDate.getGameDate(response, connection, id, dateId) if date: tournament.deleteDate(date) finally: connection.close()
def on_delete(self, request, response, id): connection = tourneyDatabase.tourneyDatabase() try: tournament = connection.tournaments.getByShortId(id) if tournament: connection.tournaments.deleteTournament(tournament) finally: connection.close()
def on_put(self, request, response, id): body = json.loads(request.stream.read()) connection = tourneyDatabase.tourneyDatabase() try: tournament = connection.tournaments.getByShortId(id) if tournament: tournament.updateTeamNames(body['group'], body['revert']) finally: connection.close()
def on_get(self, request, response): print('Loading Tournaments') connection = tourneyDatabase.tourneyDatabase() try: email = googleAuthentication.getAuthenticatedEmail(request.headers) print('Email: ' + str(email)) tournaments = connection.tournaments tournaments.ensureLoaded() response.text = tournaments.toJson(email, request.params.get('admin', 0) == '1') finally: connection.close()
def on_put(self, request, response, id, dateId): connection = tourneyDatabase.tourneyDatabase() try: date = GameDate.getGameDate(response, connection, id, dateId)[1] if date: for attempt in transaction.manager.attempts(): with attempt: date.addPitch() transaction.commit() finally: connection.close()
def on_put(self, request, response, id, dateId, pitchId): connection = tourneyDatabase.tourneyDatabase() try: pitch = Pitch.getPitch(response, connection, id, dateId, pitchId)[2] if pitch: for attempt in transaction.manager.attempts(): with attempt: pitch.clearGameTimes() transaction.commit() finally: connection.close()
def on_put(self, request, response, id, dateId): body = json.loads(request.stream.read()) connection = tourneyDatabase.tourneyDatabase() try: date = GameDate.getGameDate(response, connection, id, dateId)[1] if date: for attempt in transaction.manager.attempts(): with attempt: date.pasteGameTimes(body['clipboardText']) transaction.commit() finally: connection.close()
def on_put(self, request, response, id, dateId, pitchId): body = json.loads(request.stream.read()) connection = tourneyDatabase.tourneyDatabase() try: pitch = Pitch.getPitch(response, connection, id, dateId, pitchId)[2] if pitch: for attempt in transaction.manager.attempts(): with attempt: pitch.name = body['name'] transaction.commit() finally: connection.close()
def on_get(self, request, response, id): connection = tourneyDatabase.tourneyDatabase() try: email = googleAuthentication.getAuthenticatedEmail(request.headers) if id == 'new': tournament = Tournament(uuid.uuid4()) else: tournament = connection.tournaments.getByShortId(id) if tournament: response.text = tournament.toJson(email) finally: connection.close()
def on_get(self, request, response, id, dateId, pitchId, gameId): print('Reading Game: ' + id + '/' + dateId + '/' + pitchId + '/' + gameId) connection = tourneyDatabase.tourneyDatabase() try: email = googleAuthentication.getAuthenticatedEmail(request.headers) print('Email: ' + str(email)) (tournament, gameDate, pitch, game) = Game.getGame(response, connection, id, dateId, pitchId, gameId) # pylint: disable=unused-variable if game: # and tournament.canEdit(email): game.ensureLoadedEventLog() response.text = json.dumps(game) finally: connection.close()
def on_get(self, request, response, id): connection = tourneyDatabase.tourneyDatabase() try: email = googleAuthentication.getAuthenticatedEmail(request.headers) tournament = connection.tournaments.getByShortId(id) if tournament: statistics = PlayerStatistics(tournament) statistics.calculate() statistics.sort() result = statistics.toJsonObject() result['canEdit'] = tournament.canEdit(email) response.text = json.dumps(result) finally: connection.close()
def on_put(self, request, response): body = json.loads(request.stream.read()) connection = tourneyDatabase.tourneyDatabase() try: tournament = connection.tournaments.getById(body['id']) if not tournament: tournament = Tournament(body['id']) for attempt in transaction.manager.attempts(): with attempt: connection.tournaments.addTournament(tournament) transaction.commit() for attempt in transaction.manager.attempts(): with attempt: tournament.assign(body) transaction.commit() finally: connection.close()
def on_get(self, request, response, id): connection = tourneyDatabase.tourneyDatabase() try: email = googleAuthentication.getAuthenticatedEmail(request.headers) tournament = connection.tournaments.getByShortId(id) if tournament: #if not tournament._v_modified and tournament.id in statisticsRoute.cache: # result = statisticsRoute.cache[tournament.id] #else: statistics = Statistics(tournament) statistics.calculate() statistics.sort() result = statistics.toJsonObject() #statisticsRoute.cache[tournament.id] = result result['canEdit'] = tournament.canEdit(email) response.text = json.dumps(result) finally: connection.close()