Bug fix
Ajout du statut remplaçant pour les joueurs Possibilité d'ajouter/enlever coach et manager des équipes les joueurs peuvent être associés à plusieurs équipes au lieu d'une seule
This commit is contained in:
+29
-16
@@ -8,7 +8,7 @@ import os
|
||||
from flask import Blueprint, render_template, redirect, url_for, flash, request, jsonify, send_file
|
||||
from flask_login import login_required, current_user
|
||||
from extensions import db, hash_password
|
||||
from models import User, ROLES, ESPORT_GAMES, PlayerDisponibility, UserGamertag, GAME_PLATFORMS, Contract, OrgTeam, CoachAvailability, TeamNote, PersonalNote, OneOnOneRequest, Match, Team, TeamMember, MatchParticipant, Tryout, TryoutRegistration
|
||||
from models import User, ROLES, ESPORT_GAMES, PlayerDisponibility, UserGamertag, GAME_PLATFORMS, Contract, OrgTeam, CoachAvailability, TeamNote, PersonalNote, OneOnOneRequest, Match, Team, TeamMember, MatchParticipant, Tryout, TryoutRegistration, TeamPlayer
|
||||
from werkzeug.utils import secure_filename
|
||||
from datetime import datetime, timedelta, date as date_type
|
||||
import requests
|
||||
@@ -514,8 +514,8 @@ def can_manage_player_contract(user, player_id):
|
||||
if user.role == 'coach':
|
||||
org_team = OrgTeam.query.filter_by(coach_id=user.id).first()
|
||||
if org_team:
|
||||
player = User.query.get(player_id)
|
||||
if player and player.team_id == org_team.id:
|
||||
tp = TeamPlayer.query.filter_by(player_id=player_id, org_team_id=org_team.id).first()
|
||||
if tp:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -542,7 +542,8 @@ def list_contracts():
|
||||
if current_user.role == 'coach':
|
||||
org_team = OrgTeam.query.filter_by(coach_id=current_user.id).first()
|
||||
if org_team:
|
||||
players = User.query.filter_by(role='player', team_id=org_team.id).all()
|
||||
player_ids = [tp.player_id for tp in TeamPlayer.query.filter_by(org_team_id=org_team.id).all()]
|
||||
players = User.query.filter(User.id.in_(player_ids)).all() if player_ids else []
|
||||
else: # president or manager
|
||||
players = User.query.filter_by(role='player').all()
|
||||
|
||||
@@ -571,7 +572,11 @@ def upload_contract():
|
||||
# Get players this user can manage
|
||||
if current_user.role == 'coach':
|
||||
org_team = OrgTeam.query.filter_by(coach_id=current_user.id).first()
|
||||
players = User.query.filter_by(role='player', team_id=org_team.id).all() if org_team else []
|
||||
if org_team:
|
||||
player_ids = [tp.player_id for tp in TeamPlayer.query.filter_by(org_team_id=org_team.id).all()]
|
||||
players = User.query.filter(User.id.in_(player_ids)).all() if player_ids else []
|
||||
else:
|
||||
players = []
|
||||
else:
|
||||
players = User.query.filter_by(role='player').all()
|
||||
|
||||
@@ -598,7 +603,8 @@ def upload_contract():
|
||||
|
||||
# Get player info for folder structure
|
||||
player = User.query.get_or_404(player_id)
|
||||
team = OrgTeam.query.get(player.team_id) if player.team_id else None
|
||||
player_teams = player.get_org_teams()
|
||||
team = player_teams[0] if player_teams else None
|
||||
|
||||
# Create team folder if team exists
|
||||
if team:
|
||||
@@ -621,7 +627,7 @@ def upload_contract():
|
||||
# Create database record
|
||||
contract = Contract(
|
||||
player_id=player_id,
|
||||
team_id=player.team_id,
|
||||
team_id=team.id if team else None,
|
||||
uploaded_by_id=current_user.id,
|
||||
original_filename=original_filename,
|
||||
stored_filename=stored_filename,
|
||||
@@ -822,8 +828,9 @@ def one_on_one():
|
||||
flash('Only players can request One on One sessions.', 'danger')
|
||||
return redirect(url_for('main.dashboard'))
|
||||
|
||||
# Get player's team and coach
|
||||
org_team = OrgTeam.query.get(current_user.team_id) if current_user.team_id else None
|
||||
# Get player's teams and coach (use the first team the player is on)
|
||||
org_teams = current_user.get_org_teams()
|
||||
org_team = org_teams[0] if org_teams else None
|
||||
coach = User.query.get(org_team.coach_id) if org_team and org_team.coach_id else None
|
||||
|
||||
if not coach:
|
||||
@@ -1062,7 +1069,8 @@ def api_get_coach_availability(coach_id):
|
||||
return jsonify({'error': 'Unauthorized'}), 403
|
||||
|
||||
# Players can only view their own coach's availability
|
||||
org_team = OrgTeam.query.get(current_user.team_id) if current_user.team_id else None
|
||||
player_teams = current_user.get_org_teams()
|
||||
org_team = player_teams[0] if player_teams else None
|
||||
if org_team and org_team.coach_id != coach_id:
|
||||
return jsonify({'error': 'Unauthorized'}), 403
|
||||
|
||||
@@ -1144,7 +1152,8 @@ def manage_personal_notes():
|
||||
org_team = OrgTeam.query.filter_by(coach_id=current_user.id).first()
|
||||
players = []
|
||||
if org_team:
|
||||
players = User.query.filter_by(role='player', team_id=org_team.id).order_by(User.full_name).all()
|
||||
player_ids = [tp.player_id for tp in TeamPlayer.query.filter_by(org_team_id=org_team.id).all()]
|
||||
players = User.query.filter(User.id.in_(player_ids)).order_by(User.full_name).all() if player_ids else []
|
||||
|
||||
if request.method == 'POST':
|
||||
player_id = request.form.get('player_id', type=int)
|
||||
@@ -1200,7 +1209,8 @@ def notes_dashboard():
|
||||
org_team = OrgTeam.query.filter_by(coach_id=current_user.id).first()
|
||||
players = []
|
||||
if org_team:
|
||||
players = User.query.filter_by(role='player', team_id=org_team.id).order_by(User.full_name).all()
|
||||
player_ids = [tp.player_id for tp in TeamPlayer.query.filter_by(org_team_id=org_team.id).all()]
|
||||
players = User.query.filter(User.id.in_(player_ids)).order_by(User.full_name).all() if player_ids else []
|
||||
|
||||
# Get existing team notes
|
||||
team_notes = []
|
||||
@@ -1257,8 +1267,9 @@ def my_notes():
|
||||
flash('Only players can view their notes.', 'danger')
|
||||
return redirect(url_for('main.dashboard'))
|
||||
|
||||
# Get player's team and coach
|
||||
org_team = OrgTeam.query.get(current_user.team_id) if current_user.team_id else None
|
||||
# Get player's teams and coach (use the first team the player is on)
|
||||
player_teams = current_user.get_org_teams()
|
||||
org_team = player_teams[0] if player_teams else None
|
||||
|
||||
# Get all personal notes for this player with eager loading for relationships
|
||||
personal_notes = PersonalNote.query.filter_by(player_id=current_user.id).order_by(PersonalNote.created_at.desc()).all()
|
||||
@@ -1295,7 +1306,8 @@ def add_personal_note():
|
||||
if current_user.role == 'coach':
|
||||
org_team = OrgTeam.query.filter_by(coach_id=current_user.id).first()
|
||||
if org_team:
|
||||
players = User.query.filter_by(role='player', team_id=org_team.id).order_by(User.full_name).all()
|
||||
player_ids = [tp.player_id for tp in TeamPlayer.query.filter_by(org_team_id=org_team.id).all()]
|
||||
players = User.query.filter(User.id.in_(player_ids)).order_by(User.full_name).all() if player_ids else []
|
||||
elif current_user.role in ['president', 'manager']:
|
||||
players = User.query.filter_by(role='player').order_by(User.full_name).all()
|
||||
|
||||
@@ -1484,7 +1496,8 @@ def add_note_from_tryout(tryout_id):
|
||||
|
||||
# If coach, filter to only their team players; otherwise include all
|
||||
if org_team:
|
||||
players = User.query.filter(User.id.in_(player_ids), User.team_id == org_team.id).order_by(User.full_name).all()
|
||||
team_player_ids = [tp.player_id for tp in TeamPlayer.query.filter_by(org_team_id=org_team.id).all()]
|
||||
players = User.query.filter(User.id.in_(player_ids), User.id.in_(team_player_ids)).order_by(User.full_name).all()
|
||||
else:
|
||||
players = User.query.filter(User.id.in_(player_ids)).order_by(User.full_name).all()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user