Browse Source

Replace relation between user and player_found_objective with game_player and player_found_objective

testing
Burathar 5 years ago
parent
commit
fea0d1dc2f
  1. 10
      app/models/game_player.py
  2. 10
      app/models/objective.py
  3. 4
      app/models/player_found_objective.py
  4. 13
      app/models/user.py

10
app/models/game_player.py

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
from sqlalchemy.ext.associationproxy import association_proxy
from app import db
from app.models import Role, NotificationPlayer
from app.models import Role, NotificationPlayer, PlayerFoundObjective
class GamePlayer(db.Model):
__tablename__ = 'game_player'
@ -18,3 +18,11 @@ class GamePlayer(db.Model): @@ -18,3 +18,11 @@ class GamePlayer(db.Model):
cascade='save-update, merge, delete, delete-orphan')
notifications = association_proxy('player_notifications', 'notification',
creator=lambda notification: NotificationPlayer(notification=notification))
player_found_objectives = db.relationship(
'PlayerFoundObjective',
back_populates='game_player',
cascade='save-update, merge, delete, delete-orphan')
found_objectives = association_proxy('player_found_objectives', 'objective',
creator=lambda objective: PlayerFoundObjective(objective=objective))

10
app/models/objective.py

@ -18,15 +18,15 @@ class Objective(db.Model): @@ -18,15 +18,15 @@ class Objective(db.Model):
'PlayerFoundObjective',
back_populates='objective',
cascade='save-update, merge, delete, delete-orphan')
found_by = association_proxy('objective_found_by', 'player',
creator=lambda player: PlayerFoundObjective(player=player))
found_by = association_proxy('objective_found_by', 'game_player',
creator=lambda game_player: PlayerFoundObjective(game_player=game_player))
def set_hash(self):
self.hash = token_hex(16)
def owned_by(self, player):
'''given player is an owner of a game object is part of'''
return player in [gameplayer.player for gameplayer in self.game.game_players if gameplayer.role == Role.owner]
def owned_by(self, user):
'''given user is an owner of a game object is part of'''
return user in [gameplayer.user for gameplayer in self.game.game_players if gameplayer.role == Role.owner]
class ObjectiveMinimalEncoder(JSONEncoder):
def default(self, objective):

4
app/models/player_found_objective.py

@ -5,7 +5,7 @@ from app import db @@ -5,7 +5,7 @@ from app import db
class PlayerFoundObjective(db.Model):
__tablename__ = 'player_found_objective'
objective_id = db.Column(db.Integer, db.ForeignKey('objective.id'), primary_key=True, nullable=False, server_default='-1')
player_id = db.Column(db.Integer, db.ForeignKey('player.id'), primary_key=True, nullable=False, server_default='-1')
game_player_id = db.Column(db.Integer, db.ForeignKey('game_player.id'), primary_key=True, nullable=False, server_default='-1')
timestamp = db.Column(db.DateTime, server_default=func.now(), nullable=False)
player = db.relationship('Player', back_populates='player_found_objectives')
game_player = db.relationship('GamePlayer', back_populates='player_found_objectives')
objective = db.relationship('Objective', back_populates='objective_found_by')

13
app/models/user.py

@ -23,19 +23,8 @@ class User(UserMixin, db.Model): @@ -23,19 +23,8 @@ class User(UserMixin, db.Model):
games = association_proxy('user_games', 'game',
creator=lambda game: GamePlayer(game=game))
player_found_objectives = db.relationship(
'PlayerFoundObjective',
back_populates='player',
cascade='save-update, merge, delete, delete-orphan')
found_objectives = association_proxy('player_found_objectives', 'objective',
creator=lambda objective: PlayerFoundObjective(objective=objective))
player_notifications = db.relationship(
'NotificationPlayer',
back_populates='recipient',
cascade='save-update, merge, delete, delete-orphan')
notifications = association_proxy('player_notifications', 'notification',
creator=lambda notification: NotificationPlayer(notification=notification))
player_caught_players = db.relationship(
'PlayerCaughtPlayer',

Loading…
Cancel
Save