Browse Source

replace game.game_players with game.players

testing
Burathar 4 years ago
parent
commit
7540cbf9db
  1. 13
      app/main/routes.py
  2. 2
      app/models/objective.py
  3. 2
      app/models/user.py

13
app/main/routes.py

@ -81,7 +81,7 @@ def catch_bunny(game_name): @@ -81,7 +81,7 @@ def catch_bunny(game_name):
flash('Only hunters can catch bunnies!')
abort(403)
game_bunnies = [gameplayer for gameplayer in game.game_players if gameplayer.role == Role.bunny]
game_bunnies = [gameplayer for gameplayer in game.players if gameplayer.role == Role.bunny]
form = CatchBunnyForm()
form.bunny.choices = [(player.user.id, player.user.name) for player in game_bunnies]
@ -115,14 +115,14 @@ def add_player(game_name): @@ -115,14 +115,14 @@ def add_player(game_name):
if form_add.submit_add.data and form_add.validate_on_submit():
user = User.query.filter_by(name=form_add.name.data).first_or_404()
game.game_players.append(GamePlayer(user=user, role=Role[form_create.role.data]))
game.players.append(GamePlayer(user=user, role=Role[form_create.role.data]))
db.session.commit()
return redirect(url_for('main.game_dashboard', game_name=game.name))
if form_create.submit_create.data and form_create.validate_on_submit():
user = User(name=form_create.name.data)
user.set_auth_hash()
game.game_players.append(GamePlayer(user=user, role=Role[form_create.role.data]))
game.players.append(GamePlayer(user=user, role=Role[form_create.role.data]))
db.session.commit()
return redirect(url_for('main.game_dashboard', game_name=game.name))
@ -149,11 +149,12 @@ def game_player(game_name, username): @@ -149,11 +149,12 @@ def game_player(game_name, username):
game = Game.query.filter_by(name=game_name).first_or_404()
if not game.owned_by(current_user):
abort(403)
user = game.users
user = User.query.filter(and_(User.name == username, User.games.contains(game))).first_or_404()
gameplayer = [gameplayer for gameplayer in user.user_games if gameplayer.game == game][0]
form = PlayerUpdateForm(role=gameplayer.role.name)
player = user.player_in(game)
form = PlayerUpdateForm(role=player.role.name)
if form.validate_on_submit():
gameplayer.role = Role[form.role.data]
player.role = Role[form.role.data]
db.session.commit()
return redirect(url_for('main.game_dashboard', game_name=game.name))
return render_template('game_player.html', title=f'{user.name} in {game_name}', game=game, user=user, form=form, json=json, location_encoder=LocationEncoder)

2
app/models/objective.py

@ -27,7 +27,7 @@ class Objective(db.Model): @@ -27,7 +27,7 @@ class Objective(db.Model):
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]
return user in [gameplayer.user for gameplayer in self.game.players if gameplayer.role == Role.owner]
class ObjectiveMinimalEncoder(JSONEncoder):
def default(self, objective):

2
app/models/user.py

@ -70,7 +70,7 @@ class User(UserMixin, db.Model): @@ -70,7 +70,7 @@ class User(UserMixin, db.Model):
def owns_game_played_by(self, player):
'''Self is an owner of a game the player participates in'''
return self in [gameplayer.user for gameplayers in
[game.game_players for game in player.games]
[game.players for game in player.games]
for gameplayer in gameplayers if gameplayer.role == Role.owner]
def player_in(self, game):

Loading…
Cancel
Save