changement des notes légers: rendu le pipeline plus fluide et ai effacé des pages redondantes ou encombrantes
This commit is contained in:
+64
-5
@@ -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
|
||||
from models import User, ROLES, ESPORT_GAMES, PlayerDisponibility, UserGamertag, GAME_PLATFORMS, Contract, OrgTeam, CoachAvailability, TeamNote, PersonalNote, OneOnOneRequest, Match, Team, TeamMember, MatchParticipant, Tryout, TryoutRegistration
|
||||
from werkzeug.utils import secure_filename
|
||||
from datetime import datetime, timedelta, date as date_type
|
||||
import requests
|
||||
@@ -1132,6 +1132,60 @@ def manage_personal_notes():
|
||||
org_team=org_team)
|
||||
|
||||
|
||||
@users_bp.route('/notes', methods=['GET'])
|
||||
@login_required
|
||||
def notes_dashboard():
|
||||
"""Unified notes dashboard for coaches.
|
||||
|
||||
GET: Render the combined notes management page with both team and personal notes forms.
|
||||
|
||||
Returns:
|
||||
Response: Rendered notes dashboard template.
|
||||
"""
|
||||
if current_user.role != 'coach':
|
||||
flash('Only coaches can manage notes.', 'danger')
|
||||
return redirect(url_for('main.dashboard'))
|
||||
|
||||
# Get the coach's team
|
||||
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()
|
||||
|
||||
# Get existing team notes
|
||||
team_notes = []
|
||||
latest_team_note = None
|
||||
if org_team:
|
||||
team_notes = TeamNote.query.filter_by(org_team_id=org_team.id).order_by(TeamNote.created_at.desc()).all()
|
||||
latest_team_note = team_notes[0] if team_notes else None
|
||||
|
||||
# Get all personal notes for players on this team
|
||||
personal_notes = []
|
||||
if org_team:
|
||||
personal_notes = PersonalNote.query.filter(
|
||||
PersonalNote.player_id.in_([p.id for p in players])
|
||||
).order_by(PersonalNote.created_at.desc()).all()
|
||||
|
||||
# Get available matches and tryouts for context
|
||||
matches = []
|
||||
tryouts = []
|
||||
teams = []
|
||||
if current_user.role == 'coach' and org_team:
|
||||
tryouts = Tryout.query.filter_by(target_org_team_id=org_team.id).order_by(Tryout.date.desc()).all()
|
||||
matches = Match.query.join(Tryout).filter(Tryout.target_org_team_id == org_team.id).order_by(Match.date.desc()).all()
|
||||
teams = Team.query.order_by(Team.name).all()
|
||||
|
||||
return render_template('pages/notes.html',
|
||||
org_team=org_team,
|
||||
players=players,
|
||||
team_notes=team_notes,
|
||||
latest_team_note=latest_team_note,
|
||||
personal_notes=personal_notes,
|
||||
matches=matches,
|
||||
tryouts=tryouts,
|
||||
teams=teams)
|
||||
|
||||
|
||||
# Note source types for filtering
|
||||
NOTE_SOURCE_MATCH = 'match'
|
||||
NOTE_SOURCE_TRYOUT = 'tryout'
|
||||
@@ -1256,7 +1310,7 @@ def add_personal_note():
|
||||
db.session.add(note)
|
||||
db.session.commit()
|
||||
flash('Personal note added successfully!', 'success')
|
||||
return redirect(url_for('users.my_notes'))
|
||||
return redirect(url_for('users.notes_dashboard'))
|
||||
|
||||
return render_template('pages/add_personal_note.html',
|
||||
players=players,
|
||||
@@ -1362,6 +1416,7 @@ def add_note_from_tryout(tryout_id):
|
||||
tryout = Tryout.query.get_or_404(tryout_id)
|
||||
|
||||
# Check permissions
|
||||
org_team = None
|
||||
if current_user.role == 'coach':
|
||||
org_team = OrgTeam.query.filter_by(coach_id=current_user.id).first()
|
||||
if not org_team or (tryout.target_org_team_id and tryout.target_org_team_id != org_team.id):
|
||||
@@ -1372,8 +1427,8 @@ def add_note_from_tryout(tryout_id):
|
||||
registrations = TryoutRegistration.query.filter_by(tryout_id=tryout_id).all()
|
||||
player_ids = [r.player_id for r in registrations]
|
||||
|
||||
# If coach, filter to only their team players
|
||||
if current_user.role == 'coach' and org_team:
|
||||
# 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()
|
||||
else:
|
||||
players = User.query.filter(User.id.in_(player_ids)).order_by(User.full_name).all()
|
||||
@@ -1403,7 +1458,11 @@ def add_note_from_tryout(tryout_id):
|
||||
flash('Personal note added successfully!', 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
# Allow pre-selecting a player via query parameter
|
||||
preselected_player_id = request.args.get('player_id', type=int)
|
||||
|
||||
return render_template('pages/add_note_from_tryout.html',
|
||||
tryout=tryout,
|
||||
players=players,
|
||||
team_notes=team_notes)
|
||||
team_notes=team_notes,
|
||||
preselected_player_id=preselected_player_id)
|
||||
|
||||
Reference in New Issue
Block a user