|
|
|
@ -178,19 +178,23 @@ def add_player(game_name):
@@ -178,19 +178,23 @@ def add_player(game_name):
|
|
|
|
|
game = Game.query.filter_by(name=game_name).first_or_404() |
|
|
|
|
if not game.owned_by(current_user): |
|
|
|
|
abort(403) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
form_add = PlayerAddForm() |
|
|
|
|
form_add.role.choices = [(role.value, role.name) for role in Role] |
|
|
|
|
form_create = UserCreateForm() |
|
|
|
|
form_create.role.choices = [(role.value, role.name) for role in Role] |
|
|
|
|
|
|
|
|
|
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.players.append(GamePlayer(user=user, role=Role[form_create.role.data])) |
|
|
|
|
game.players.append(GamePlayer(user=user, role=Role(form_add.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.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)) |
|
|
|
|
|
|
|
|
@ -224,11 +228,13 @@ def game_player(game_name, username):
@@ -224,11 +228,13 @@ def game_player(game_name, username):
|
|
|
|
|
# pylint: disable=no-member |
|
|
|
|
form = PlayerUpdateForm(role=player.role.name) |
|
|
|
|
form.role.choices = [(role.value, role.name) for role in Role] |
|
|
|
|
if request.method == 'GET': |
|
|
|
|
form.role.default = player.role.value |
|
|
|
|
form.process() |
|
|
|
|
|
|
|
|
|
if form.validate_on_submit(): |
|
|
|
|
player.role = Role[form.role.data] |
|
|
|
|
player.role = Role(form.role.data) |
|
|
|
|
print(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}', player=player, form=form, json=json, location_encoder=LocationEncoder) |
|
|
|
|