Example #1
0
    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()
Example #2
0
 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()
Example #3
0
 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()
Example #4
0
    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()
Example #5
0
 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()
Example #6
0
    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()
Example #7
0
    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()