From f387cd5b9bb8f4632b14b87e8a799c886e626dad Mon Sep 17 00:00:00 2001 From: Burathar Date: Sun, 19 Jul 2020 17:00:59 +0200 Subject: [PATCH] rename game_players to players, add bunnies method --- app/models/game.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/models/game.py b/app/models/game.py index 661617a..22b2539 100644 --- a/app/models/game.py +++ b/app/models/game.py @@ -11,12 +11,10 @@ class Game(db.Model): state = db.Column(db.Enum(GameState), server_default=GameState(1).name, nullable=False) start_time = db.Column(db.DateTime) end_time = db.Column(db.DateTime) - game_players = db.relationship( + players = db.relationship( 'GamePlayer', back_populates='game', cascade="save-update, merge, delete, delete-orphan") - players = association_proxy('game_players', 'user', - creator=lambda user: GamePlayer(user=user)) users = association_proxy('game_players', 'user', creator=lambda user: GamePlayer(user=user)) objectives = db.relationship( @@ -31,19 +29,22 @@ class Game(db.Model): cascade="save-update, merge, delete, delete-orphan") def last_player_locations(self): - return [user.last_location(self) for user in self.players if user.locations] - - def bunnies(self): # pylint: disable=not-an-iterable - return [gameplayer.user for gameplayer in self.game_players if gameplayer.role == Role.bunny] + return [player.last_location() for player in self.players if player.user.locations] def last_locations(self, players): locations = [] for player in players: + if isinstance(player, GamePlayer): + player = player.user locations.append(player.last_location(self)) return locations + def bunnies(self): + # pylint: disable=not-an-iterable + return [gameplayer for gameplayer in self.players if gameplayer.role == Role.bunny] + def owned_by(self, user): # pylint: disable=not-an-iterable '''given user is an owner of this game''' - return user in [gameplayer.user for gameplayer in self.game_players if gameplayer.role == Role.owner] + return user in [gameplayer.user for gameplayer in self.players if gameplayer.role == Role.owner]