Ajout d'une catégorie jeux dans le tryouts, chacun des jeux offre des rôles différents pour les membres d'équipes. Remodelage du code un peu et ajout de docu
This commit is contained in:
+70
-1
@@ -1,3 +1,8 @@
|
||||
"""Organization team management routes.
|
||||
|
||||
This module handles CRUD operations for organization teams and player assignments.
|
||||
"""
|
||||
|
||||
from flask import Blueprint, render_template, redirect, url_for, flash, request
|
||||
from flask_login import login_required, current_user
|
||||
from extensions import db
|
||||
@@ -5,9 +10,18 @@ from models import OrgTeam, User
|
||||
|
||||
teams_bp = Blueprint('teams', __name__, url_prefix='/teams')
|
||||
|
||||
|
||||
@teams_bp.route('')
|
||||
@login_required
|
||||
def list_teams():
|
||||
"""List all organization teams visible to the current user.
|
||||
|
||||
Coaches see only their assigned team. Players and scouts see all teams.
|
||||
Managers and presidents see all teams and can manage them.
|
||||
|
||||
Returns:
|
||||
Response: Rendered teams list template.
|
||||
"""
|
||||
can_manage = current_user.can_manage_teams()
|
||||
|
||||
if current_user.role == 'coach':
|
||||
@@ -24,9 +38,19 @@ def list_teams():
|
||||
all_players = User.query.filter_by(role='player').order_by(User.full_name).all()
|
||||
return render_template('pages/teams.html', teams=teams, coaches=coaches, all_players=all_players, can_manage=can_manage)
|
||||
|
||||
|
||||
@teams_bp.route('/create', methods=['POST'])
|
||||
@login_required
|
||||
def create_team():
|
||||
"""Create a new organization team.
|
||||
|
||||
Args:
|
||||
name: Team name from form.
|
||||
coach_id: Optional coach assignment from form.
|
||||
|
||||
Returns:
|
||||
Response: Redirect to teams list with status message.
|
||||
"""
|
||||
if not current_user.can_manage_teams():
|
||||
flash('You do not have permission to create teams.', 'danger')
|
||||
return redirect(url_for('teams.list_teams'))
|
||||
@@ -53,9 +77,20 @@ def create_team():
|
||||
flash(f'Team "{name}" created successfully!', 'success')
|
||||
return redirect(url_for('teams.list_teams'))
|
||||
|
||||
|
||||
@teams_bp.route('/<int:team_id>/edit', methods=['POST'])
|
||||
@login_required
|
||||
def edit_team(team_id):
|
||||
"""Edit an existing organization team.
|
||||
|
||||
Args:
|
||||
team_id: The ID of the team to edit.
|
||||
name: New team name from form.
|
||||
coach_id: New coach assignment from form.
|
||||
|
||||
Returns:
|
||||
Response: Redirect to teams list with status message.
|
||||
"""
|
||||
team = OrgTeam.query.get_or_404(team_id)
|
||||
if not current_user.can_manage_this_org_team(team):
|
||||
flash('You do not have permission to edit this team.', 'danger')
|
||||
@@ -79,9 +114,21 @@ def edit_team(team_id):
|
||||
flash(f'Team "{name}" updated successfully!', 'success')
|
||||
return redirect(url_for('teams.list_teams'))
|
||||
|
||||
|
||||
@teams_bp.route('/<int:team_id>/delete', methods=['POST'])
|
||||
@login_required
|
||||
def delete_team(team_id):
|
||||
"""Delete an organization team.
|
||||
|
||||
Removes the team and clears its target_org_team_id reference from
|
||||
any linked tryouts before deletion.
|
||||
|
||||
Args:
|
||||
team_id: The ID of the team to delete.
|
||||
|
||||
Returns:
|
||||
Response: Redirect to teams list with status message.
|
||||
"""
|
||||
if not current_user.can_manage_teams():
|
||||
flash('You do not have permission to delete teams.', 'danger')
|
||||
return redirect(url_for('teams.list_teams'))
|
||||
@@ -102,9 +149,21 @@ def delete_team(team_id):
|
||||
flash(f'Team "{name}" deleted successfully.', 'success')
|
||||
return redirect(url_for('teams.list_teams'))
|
||||
|
||||
|
||||
@teams_bp.route('/<int:team_id>/add_player', methods=['POST'])
|
||||
@login_required
|
||||
def add_player(team_id):
|
||||
"""Add a player to an organization team.
|
||||
|
||||
If player is already on another team, they will be moved.
|
||||
|
||||
Args:
|
||||
team_id: The ID of the team to add the player to.
|
||||
player_id: The ID of the player to add.
|
||||
|
||||
Returns:
|
||||
Response: Redirect to teams list with status message.
|
||||
"""
|
||||
team = OrgTeam.query.get_or_404(team_id)
|
||||
if not current_user.can_manage_this_org_team(team):
|
||||
flash('Permission denied.', 'danger')
|
||||
@@ -134,9 +193,19 @@ def add_player(team_id):
|
||||
flash(f'{player.full_name} added to {team.name}!', 'success')
|
||||
return redirect(url_for('teams.list_teams'))
|
||||
|
||||
|
||||
@teams_bp.route('/<int:team_id>/remove_player/<int:player_id>', methods=['POST'])
|
||||
@login_required
|
||||
def remove_player(team_id, player_id):
|
||||
"""Remove a player from an organization team.
|
||||
|
||||
Args:
|
||||
team_id: The ID of the team.
|
||||
player_id: The ID of the player to remove.
|
||||
|
||||
Returns:
|
||||
Response: Redirect to teams list with status message.
|
||||
"""
|
||||
team = OrgTeam.query.get_or_404(team_id)
|
||||
if not current_user.can_manage_this_org_team(team):
|
||||
flash('Permission denied.', 'danger')
|
||||
@@ -151,4 +220,4 @@ def remove_player(team_id, player_id):
|
||||
player.team_id = None
|
||||
db.session.commit()
|
||||
flash(f'{player.full_name} removed from {team.name}.', 'success')
|
||||
return redirect(url_for('teams.list_teams'))
|
||||
return redirect(url_for('teams.list_teams'))
|
||||
Reference in New Issue
Block a user