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