tournament: add: game call func when finished
This commit is contained in:
@ -90,6 +90,9 @@ class TournamentRoom:
|
||||
self._member_list.add(member)
|
||||
|
||||
return member
|
||||
|
||||
def set_game_as_finished(self, game: GameModel):
|
||||
raise NotImplemented()
|
||||
|
||||
def get_participants_profiles(self) -> list[ProfileModel]:
|
||||
return [participant._socket.user.profilemodel for participant in self.get_participants()]
|
||||
|
@ -53,7 +53,7 @@ class TournamentModel(models.Model):
|
||||
return game
|
||||
|
||||
def get_games(self) -> list[GameModel]:
|
||||
return [tournament_game.game for tournament_game in TournamentGameModel.objects.filter(tournament=self)]
|
||||
return [games for games in self.get_games_by_round(i for i in range(1, self.round))]
|
||||
|
||||
def get_games_by_round(self, round: int) -> list[GameModel]:
|
||||
return [tournament_game.game for tournament_game in TournamentGameModel.objects.filter(tournament=self, round=round)]
|
||||
|
@ -13,16 +13,20 @@ class TournamentSerializer(serializers.ModelSerializer):
|
||||
state = serializers.SerializerMethodField(read_only=True, required=False)
|
||||
participants = serializers.SerializerMethodField(read_only=True, required=False)
|
||||
round = serializers.ReadOnlyField()
|
||||
games = serializers.SerializerMethodField(read_only=True, required=False)
|
||||
started = serializers.ReadOnlyField()
|
||||
finished = serializers.ReadOnlyField()
|
||||
name = serializers.CharField(default="")
|
||||
|
||||
class Meta:
|
||||
model = TournamentModel
|
||||
fields = ["name", "nb_participants", "round", "started", "finished", "id", "state", "participants"]
|
||||
fields = ["name", "nb_participants", "round", "started", "finished", "id", "state", "participants", "games"]
|
||||
|
||||
def get_participants(self, instance: TournamentModel):
|
||||
return ProfileSerializer(instance.get_participants(), many=True).data
|
||||
|
||||
def get_games(self, instance: TournamentModel):
|
||||
return GameSerializer(instance.get_games(), many=True).data
|
||||
|
||||
def get_state(self, instance: TournamentModel):
|
||||
return ["waiting", "started", "finished"][instance.started + instance.finished]
|
||||
|
Reference in New Issue
Block a user