def edit_ranking(id_player, new_ranking): user = Query() db.table("players").update({"ranking": new_ranking}, user.identity == int(id_player)) for player in players: if player.identity == id_player: player.edit_ranking(new_ranking)
def get_identity(what_we_looking_for): """take a table on attribute and return the 1st free id """ list_of_identity = [] identity = 1 table = db.table(what_we_looking_for).all() for i in range(len(table)): list_of_identity.append(table[i]["identity"]) while identity in list_of_identity: identity += 1 return identity
def scooting_tournament(): menu = {"cases": [], "string": ""} listing = db.table("tournament").all() for i in range(len(listing)): menu["cases"].append(str(i + 1)) menu[ "string"] += f"{listing[i]['name']} {listing[i]['starting_date']} ({i + 1})\n" if menu["string"] == "": return 0 return menu
def scooting_player(): menu = {"cases": [], "string": ""} listing = db.table("players").all() for i in range(len(listing)): menu["cases"].append(str(i + 1)) menu[ "string"] += f"{listing[i]['lastname']} {listing[i]['firstname']} ({i + 1})\n" if menu["string"] == "": return 0 return menu
def loading_player(identity): listing = db.table("players").all() player_to_load = listing[int(identity) - 1] return { "lastname": player_to_load["lastname"], "firstname": player_to_load["firstname"], "date_of_birth": player_to_load["date_of_birth"], "gender": player_to_load["gender"], "ranking": player_to_load["ranking"], "identity": player_to_load["identity"], "tournament_point": player_to_load["tournament_point"] }
def saving_tournament(tournament): """ :param tournament: tournament instance :return: insert this tournamenent in database """ for ronde in tournament.rounds: ronde.serialization() tournament.edit_serialized_round(ronde.serialized_round) for player in players: tournament.edit_players_id_by_one(player.identity) tournament.serialization() tournament_table = db.table("tournament") tournament_db = Query() results = db.table("tournament").search( tournament_db.identity == tournament.identity) if not results: tournament_table.insert(tournament.serialized_tournament) else: db.table("tournament").update( { "serialized_round": tournament.serialized_tournament["serialized_round"] }, tournament_db.identity == tournament.identity)
def loading_tournament(identity): listing = db.table("tournament").all() tournament_to_load = listing[int(identity) - 1] return { "identity": tournament_to_load["identity"], "name": tournament_to_load["name"], "place": tournament_to_load["place"], "starting_date": tournament_to_load["starting_date"], "ending_date": tournament_to_load["ending_date"], "kind": tournament_to_load["kind"], "description": tournament_to_load["description"], "number_of_round": tournament_to_load["number_of_round"], "players_id": tournament_to_load["players_id"], "serialized_round": tournament_to_load["serialized_round"] }
def saving_player(player): """ :param player: player instance :return: insert this player in database """ player.serialization() players_table = db.table("players") player_db = Query() results = db.table("players").search(player_db.identity == player.identity) if not results: players_table.insert(player.serialized) else: db.table("players").update({"ranking": player.serialized["ranking"]}, player_db.identity == player.identity) db.table("players").update( {"tournament_point": player.serialized["tournament_point"]}, player_db.identity == player.identity)
def get_db(table): return db.table(table).all()
def scooting_player_id(player_to_scoot): listing = db.table("players").all() for i in range(len(listing)): if listing[i]["lastname"] == player_to_scoot.lastname and listing[i][ "firstname"] == player_to_scoot.firstname: return listing[i]["identity"]