Exemplo n.º 1
0
    def POST(self, id_tournament):
        list_inputs = web.input()
        # Returns the number of players already register in a tournament
        numberPlayerInTournament = trn.numberPlayerInTournament(id_tournament)
        # Returns the number of players allowed by tournament
        numberPlayerByTournament = trn.numberPlayerByTournament(id_tournament)
        # Get the number of inputs selected in form less one because of submit input
        numberOfInputs = len(list_inputs) - 1

        if numberOfInputs + int(numberPlayerInTournament) <= int(numberPlayerByTournament):
            for value in list_inputs:
                if value != "save":
                    # Records a player for each tournament
                    trn.assignPlayerTournament(int(id_tournament), int(value[6:]))
            url = "/players_tournament/%d" % int(id_tournament)
            raise web.seeother(url)

        # Returns the players for each tournament
        players = trn.reportPlayers(id_tournament)
        # Create a list of Checkboxs uses to assign players to a tournament
        for player in players:
            name = "player%d" % player[0]
            self.dynamic.add_input(web.form.Checkbox(name, description=player[1], value=player[0]))
        self.dynamic.add_input(
            web.form.Button("save", type="submit", description="Save", class_="btn btn-lg btn-warning pull-right")
        )
        return render.assign_players(id_tournament, self.dynamic)
Exemplo n.º 2
0
    def GET(self, id_tournament):
        # Returns the number of players already register in a tournament
        numberPlayerInTournament = trn.numberPlayerInTournament(id_tournament)
        # Returns the number of players allowed by tournament
        numberPlayerByTournament = trn.numberPlayerByTournament(id_tournament)

        # Validates if a number of players register in a tournament is less than a number
        # of players allowed in a tournament

        if int(numberPlayerInTournament) < int(numberPlayerByTournament):
            # Returns list of players register in the app
            players = trn.reportPlayers(id_tournament)
            # Create a list of Checkboxs uses to assign players to a tournament
            for player in players:
                name = "player%d" % player[0]
                self.dynamic.add_input(web.form.Checkbox(name, description=player[1], value=player[0]))
            self.dynamic.add_input(
                web.form.Button("save", type="submit", description="Save", class_="btn btn-lg btn-warning pull-right")
            )
            return render.assign_players(id_tournament, self.dynamic)
        return render.assign_players(id_tournament, self.dynamic)