Changement du refresh handler, soft reset d'ajouter sur beaucoup de formulaire de modification
CI - Security, Lint & Tests / validate (push) Failing after 1m3s
CI - Security, Lint & Tests / validate (push) Failing after 1m3s
This commit is contained in:
+46
-45
@@ -32,6 +32,7 @@ from app.models import (
|
||||
TryoutRegistration,
|
||||
User,
|
||||
)
|
||||
from app.responders import respond_after_change
|
||||
from app.time_utils import utc_now_naive
|
||||
from app.validators import (
|
||||
PlayerSelectionSchema,
|
||||
@@ -477,31 +478,31 @@ def register_for_tryout(tryout_id):
|
||||
"""Register a player for a tryout. Only Players can self-register."""
|
||||
if not isinstance(current_user, Player):
|
||||
flash(_('Only players can register for tryouts.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
tryout = locked_tryout_or_404(tryout_id)
|
||||
|
||||
if tryout.status not in ['upcoming', 'in_progress']:
|
||||
flash(_('This tryout is not accepting registrations.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
existing = TryoutRegistration.query.filter_by(
|
||||
tryout_id=tryout_id, player_id=current_user.id
|
||||
).first()
|
||||
if existing:
|
||||
flash(_('You are already registered for this tryout.'), 'info')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if tryout.max_players:
|
||||
count = TryoutRegistration.query.filter_by(tryout_id=tryout_id).count()
|
||||
if count >= tryout.max_players:
|
||||
flash(_('This tryout is full.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
registration = TryoutRegistration(tryout_id=tryout_id, player_id=current_user.id)
|
||||
db.session.add(registration)
|
||||
db.session.commit()
|
||||
flash(_('Successfully registered for tryout!'), 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>/status', methods=['POST'])
|
||||
@@ -514,7 +515,7 @@ def update_status(tryout_id):
|
||||
'Tryouts are currently closed. An admin must open tryouts before changes can be made.',
|
||||
'danger',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
flash(_('Permission denied.'), 'danger')
|
||||
@@ -523,12 +524,12 @@ def update_status(tryout_id):
|
||||
data = TryoutStatusSchema().load(form_payload(list_fields=()))
|
||||
except ValidationError as err:
|
||||
flash_validation_errors(err)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
tryout.status = data['status']
|
||||
db.session.commit()
|
||||
flash(_('Tryout status updated to %(new_status)s.', new_status=data['status']), 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>/registration/<int:player_id>/status', methods=['POST'])
|
||||
@@ -541,7 +542,7 @@ def update_registration_status(tryout_id, player_id):
|
||||
'Tryouts are currently closed. An admin must open tryouts before changes can be made.',
|
||||
'danger',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
flash(_('Permission denied.'), 'danger')
|
||||
@@ -554,12 +555,12 @@ def update_registration_status(tryout_id, player_id):
|
||||
data = TryoutRegistrationStatusSchema().load(form_payload(list_fields=()))
|
||||
except ValidationError as err:
|
||||
flash_validation_errors(err)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
registration.status = data['status']
|
||||
db.session.commit()
|
||||
flash(_('Registration status updated.'), 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>/register_player', methods=['POST'])
|
||||
@@ -572,20 +573,20 @@ def register_player(tryout_id):
|
||||
'Tryouts are currently closed. An admin must open tryouts before changes can be made.',
|
||||
'danger',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
flash(_('Permission denied.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
try:
|
||||
data = PlayerSelectionSchema().load(form_payload())
|
||||
except ValidationError as err:
|
||||
flash_validation_errors(err)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not data['player_id']:
|
||||
flash(_('Please select a player.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
# Same two checks as the team roster (SEC-16): the right role, and an
|
||||
# account that has not been deactivated. The select this comes from now
|
||||
@@ -593,7 +594,7 @@ def register_player(tryout_id):
|
||||
player = db.session.get(User, data['player_id'])
|
||||
if not player or not isinstance(player, Player) or not player.is_active_account:
|
||||
flash(_('Can only register players.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
existing = TryoutRegistration.query.filter_by(tryout_id=tryout_id, player_id=player.id).first()
|
||||
if existing:
|
||||
@@ -601,19 +602,19 @@ def register_player(tryout_id):
|
||||
_('%(username)s is already registered for this tryout.', username=player.username),
|
||||
'info',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if tryout.max_players:
|
||||
count = TryoutRegistration.query.filter_by(tryout_id=tryout_id).count()
|
||||
if count >= tryout.max_players:
|
||||
flash(_('This tryout is full.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
registration = TryoutRegistration(tryout_id=tryout_id, player_id=player.id)
|
||||
db.session.add(registration)
|
||||
db.session.commit()
|
||||
flash(_('%(username)s registered for tryout!', username=player.username), 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>/remove_player/<int:player_id>', methods=['POST'])
|
||||
@@ -626,7 +627,7 @@ def remove_player(tryout_id, player_id):
|
||||
'Tryouts are currently closed. An admin must open tryouts before changes can be made.',
|
||||
'danger',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
flash(_('Permission denied.'), 'danger')
|
||||
@@ -656,7 +657,7 @@ def remove_player(tryout_id, player_id):
|
||||
|
||||
db.session.commit()
|
||||
flash(_('%(username)s removed from tryout.', username=player.username), 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>/team/create', methods=['POST'])
|
||||
@@ -669,23 +670,23 @@ def create_team(tryout_id):
|
||||
'Tryouts are currently closed. An admin must open tryouts before changes can be made.',
|
||||
'danger',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
flash(_('Permission denied.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
try:
|
||||
data = TryoutTeamSchema().load(form_payload(list_fields=()))
|
||||
except ValidationError as err:
|
||||
flash_validation_errors(err)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
team = Team(tryout_id=tryout_id, name=data['team_name'], created_by=current_user.id)
|
||||
db.session.add(team)
|
||||
db.session.commit()
|
||||
flash(_('Team "%(team_name)s" created!', team_name=data['team_name']), 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>/team/<int:team_id>/add', methods=['POST'])
|
||||
@@ -699,11 +700,11 @@ def add_to_team(tryout_id, team_id):
|
||||
'Tryouts are currently closed. An admin must open tryouts before changes can be made.',
|
||||
'danger',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
flash(_('Permission denied.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
# The two ids arrive independently in the URL. Without this check, being
|
||||
# allowed to manage tryout A was enough to modify a team belonging to
|
||||
@@ -715,7 +716,7 @@ def add_to_team(tryout_id, team_id):
|
||||
data = TryoutTeamMemberSchema().load(form_payload(list_fields=()))
|
||||
except ValidationError as err:
|
||||
flash_validation_errors(err)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
player_id = data['player_id']
|
||||
|
||||
# Only players registered for this tryout may be placed on its teams.
|
||||
@@ -725,7 +726,7 @@ def add_to_team(tryout_id, team_id):
|
||||
)
|
||||
if not is_registered:
|
||||
flash(_('That player is not registered for this tryout.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
existing = TeamMember.query.filter_by(team_id=team_id, player_id=player_id).first()
|
||||
if existing:
|
||||
@@ -735,7 +736,7 @@ def add_to_team(tryout_id, team_id):
|
||||
db.session.add(member)
|
||||
db.session.commit()
|
||||
flash(_('Player added to team!'), 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>/team/<int:team_id>/edit', methods=['POST'])
|
||||
@@ -749,11 +750,11 @@ def edit_team(tryout_id, team_id):
|
||||
'Tryouts are currently closed. An admin must open tryouts before changes can be made.',
|
||||
'danger',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
flash(_('Permission denied.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if team.tryout_id != tryout_id:
|
||||
abort(404)
|
||||
@@ -762,12 +763,12 @@ def edit_team(tryout_id, team_id):
|
||||
data = TryoutTeamSchema().load(form_payload(list_fields=()))
|
||||
except ValidationError as err:
|
||||
flash_validation_errors(err)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
team.name = data['team_name']
|
||||
db.session.commit()
|
||||
flash(_('Team renamed to "%(team_name)s".', team_name=data['team_name']), 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>/team/<int:team_id>/delete', methods=['POST'])
|
||||
@@ -781,11 +782,11 @@ def delete_team(tryout_id, team_id):
|
||||
'Tryouts are currently closed. An admin must open tryouts before changes can be made.',
|
||||
'danger',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
flash(_('Permission denied.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if team.tryout_id != tryout_id:
|
||||
abort(404)
|
||||
@@ -811,7 +812,7 @@ def delete_team(tryout_id, team_id):
|
||||
db.session.delete(team)
|
||||
db.session.commit()
|
||||
flash(_('Team "%(name)s" deleted.', name=name), 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>/team/<int:team_id>/remove/<int:player_id>', methods=['POST'])
|
||||
@@ -825,11 +826,11 @@ def remove_from_team(tryout_id, team_id, player_id):
|
||||
'Tryouts are currently closed. An admin must open tryouts before changes can be made.',
|
||||
'danger',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
flash(_('Permission denied.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if team.tryout_id != tryout_id:
|
||||
abort(404)
|
||||
@@ -846,7 +847,7 @@ def remove_from_team(tryout_id, team_id, player_id):
|
||||
).delete(synchronize_session=False)
|
||||
db.session.commit()
|
||||
flash(_('Player removed from team.'), 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
|
||||
@tryouts_bp.route(
|
||||
@@ -863,11 +864,11 @@ def update_member_position(tryout_id, team_id, member_id):
|
||||
'Tryouts are currently closed. An admin must open tryouts before changes can be made.',
|
||||
'danger',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
flash(_('Permission denied.'), 'danger')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if team.tryout_id != tryout_id or member.team_id != team_id:
|
||||
abort(404)
|
||||
@@ -876,12 +877,12 @@ def update_member_position(tryout_id, team_id, member_id):
|
||||
data = TryoutTeamMemberPositionSchema().load(form_payload(list_fields=()))
|
||||
except ValidationError as err:
|
||||
flash_validation_errors(err)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
member.position = data['position'] or None
|
||||
db.session.commit()
|
||||
flash(_('Position updated.'), 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>/delete', methods=['POST'])
|
||||
@@ -894,7 +895,7 @@ def delete_tryout(tryout_id):
|
||||
'Tryouts are currently closed. An admin must open tryouts before changes can be made.',
|
||||
'danger',
|
||||
)
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
return respond_after_change(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
flash(_('You do not have permission to delete this tryout.'), 'danger')
|
||||
|
||||
Reference in New Issue
Block a user