Ejemplo n.º 1
0
    def player(self, team_code=None, **unknown_args):
        page = get_html("player.html")
        if not force_qr_scan:
            page = page.replace('input readonly', 'input')
        if team_code:
            if not service.is_team(team_code):
                page = page.replace("{teamcode}", team_code)
                return html.show(page, "wrong-teamcode")
            cherrypy.session['player_teamcode'] = team_code
        else:
            team_code = cherrypy.session.get('player_teamcode', None)
        if team_code:
            log.info("Team {} checked its score".format(team_code))
            section = service.get_section(team_code)
            page = page.replace("{teamcode}", team_code)
            page = page.replace("{section-name}", section)
            page = page.replace(
                "{section-score}",
                str(round(service.get_section_score(section), 2)))
            page = page.replace("{team-score}",
                                str(service.get_score(team_code)[0]))
            page = html.show(page, "scores")
        else:
            page = page.replace("{teamcode}", "")

        return page
Ejemplo n.º 2
0
 def get_opponent_code(self, game_number, team_code):
     try:
         int_game_number = int(game_number)
     except ValueError:
         log.error(
             "{} unsuccessfully tried to get the opponent of team code {} but the game number {} is not an integer"
             .format(str(cherrypy.request.remote.ip), team_code,
                     game_number))
         return ""
     if not service.is_game(int(int_game_number)):
         log.error(
             "{} unsuccessfully tried to get the opponent of team code {} but the game number {} was wrong"
             .format(str(cherrypy.request.remote.ip), team_code,
                     int_game_number))
         return ""
     if not service.is_team(team_code):
         log.error(
             "{} unsuccessfully tried to get the opponent of at game {} but the team number {} was wrong"
             .format(str(cherrypy.request.remote.ip), int_game_number,
                     team_code))
         return ""
     try:
         return service.get_opponent_code(int_game_number, team_code)
     except DoesNotExist:
         msg = "Pas de combinaison trouvée pour {} au jeu {}".format(
             team_code, int_game_number)
         log.info(msg)
         return "Error: " + msg
Ejemplo n.º 3
0
 def get_team_section(self, team_code):
     if service.is_team(team_code):
         return service.get_section(team_code)
     else:
         log.error(
             "{} unsuccessfully tried to get the section name of team code {}"
             .format(str(cherrypy.request.remote.ip), team_code))
         return "Error: il n'y a pas de team {}".format(team_code)
Ejemplo n.º 4
0
 def get_game_number(self, team1_code, team2_code):
     if not service.is_team(team1_code):
         log.error(
             "{} unsuccessfully tried to get the game number of team code {} but the opponent team code {} was wrong"
             .format(str(cherrypy.request.remote.ip), team2_code,
                     team1_code))
         return ""
     if not service.is_team(team2_code):
         log.error(
             "{} unsuccessfully tried to get the game number of team code {} but the opponent team code {} was wrong"
             .format(str(cherrypy.request.remote.ip), team1_code,
                     team2_code))
         return ""
     try:
         return str(
             Match.objects(players_code__all=[team1_code, team2_code
                                              ]).get().game_number)
     except DoesNotExist:
         msg = "Les équipes {} et {} ne sont pas censées jouer ensemble".format(
             team1_code, team2_code)
         log.info(msg)
         return "Error: " + msg
Ejemplo n.º 5
0
    def leader(self,
               password=None,
               team1_code=None,
               team2_code=None,
               game_number=None,
               winner=None,
               confirmed=None,
               **unknown_args):
        login_page = request_login("/leader", password, 0)
        if login_page:
            return login_page

        notification = ""
        warning = ""
        page = get_html("leader.html")
        if not force_qr_scan:
            page = page.replace('input readonly', 'input')
        if team1_code and team2_code and game_number:
            wrong_team1 = False if service.is_team(team1_code) else True
            wrong_team2 = False if service.is_team(team2_code) else True
            wrong_game = False if service.is_game(game_number) else True
            good_values = False if wrong_game or wrong_team1 or wrong_team2 else True
            if winner and team2_code == winner:
                team2_code = team1_code
                team1_code = winner
            if confirmed and good_values:
                cherrypy.session['game_number'] = game_number
                try:
                    if winner == "even":
                        service.set_even(int(game_number), team1_code,
                                         team2_code)
                    else:
                        service.set_winner(int(game_number), team1_code,
                                           team2_code)
                    notification = 'Le score a bien été enregistré'
                except Exception:
                    log.exception(
                        "Something bad occurred while an user tried to set a score"
                    )
                    warning = "Le score n'a pas pu être enregistr&eacute.\n" \
                              "Merci de le signaler à l'administrateur.;"
            else:
                # confirm page
                page = get_html("confirm_score.html")
                page = page.replace('{game_number}', str(game_number))
                page = page.replace('{team1_code}', team1_code)
                page = page.replace('{team2_code}', team2_code)
                if winner == "even":
                    page = page.replace('{team1_title}', "Team 1")
                    page = page.replace('{team2_title}', "Team 2")
                    page = page.replace(
                        '{even-hidden-input}',
                        '<input type="hidden" name="winner" value="even"/>')
                    page = html.show(page, "equally-scored")
                else:
                    page = page.replace('{team1_title}', "Gagnant")
                    page = page.replace('{team2_title}', "Perdant")
                    page = page.replace('{even-hidden-input}', '')
                try:
                    match = Match.objects(game_number=game_number,
                                          players_code=team1_code).get()
                    page = page.replace("{time}", str(match.time))
                    page = page.replace("{schedule}", match.schedule)
                    if match.recorded:
                        page = html.show(page, "previous-score")
                        if match.even:
                            page = html.show(page, "previous-equally-scored")
                            page = page.replace('{previous_team1_title}',
                                                "Team 1")
                            page = page.replace('{previous_team2_title}',
                                                "Team 2")
                            page = page.replace('{previous_team1_code}',
                                                match.players_code[0])
                            page = page.replace('{previous_team2_code}',
                                                match.players_code[1])
                        else:
                            page = page.replace('{previous_team1_title}',
                                                "Gagnant")
                            page = page.replace('{previous_team2_title}',
                                                "Perdant")
                            page = page.replace('{previous_team1_code}',
                                                match.winner)
                            page = page.replace('{previous_team2_code}',
                                                match.loser)
                except Exception:
                    log.exception(
                        "An user tried to encode an non existing combination: game_number={}, team1={}, "
                        "team2={}".format(game_number, team1_code, team2_code))
                    warning = "Cette combinaison n'existe pas"
                    page = html.hide(page, "time-row")
                    page = html.hide(page, "confirm-score")
                    page = html.show(page, "retry-button")
                finally:
                    page = page.replace('{previous_team1_title}', "Team 1")
                    page = page.replace('{previous_team2_title}', "Team 2")
                    page = page.replace('{previous_team1_code}', "")
                    page = page.replace('{previous_team2_code}', "")

        page = page.replace("{game-number}",
                            cherrypy.session.get('game_number', ""))
        page = page.replace('{notification}', notification)
        page = page.replace('{warning}', warning)
        return page