Régler problèmes d'affichage des matchs récents:
Ajout des match qui arrivent pour les coach, president et manager Légèrement alléger la quantité de pages (merge certaines ensembles)
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+63
-39
@@ -52,12 +52,24 @@ def dashboard():
|
||||
stats['completed_tryouts'] = Tryout.query.filter_by(status='completed').count()
|
||||
stats['recent_users'] = User.query.order_by(User.created_at.desc()).limit(10).all()
|
||||
stats['recent_tryouts'] = Tryout.query.order_by(Tryout.created_at.desc()).limit(10).all()
|
||||
today = date.today()
|
||||
stats['upcoming_matches'] = Match.query.filter(
|
||||
Match.status == 'scheduled',
|
||||
Match.date >= today
|
||||
).order_by(Match.date, Match.start_time).limit(5).all()
|
||||
|
||||
elif user.role == 'manager':
|
||||
stats['total_tryouts'] = Tryout.query.filter_by(created_by=user.id).count()
|
||||
stats['active_tryouts'] = Tryout.query.filter_by(created_by=user.id, status='in_progress').count()
|
||||
stats['total_evaluations'] = Evaluation.query.filter_by(evaluator_id=user.id).count()
|
||||
stats['my_tryouts'] = Tryout.query.filter_by(created_by=user.id).order_by(Tryout.date.desc()).limit(5).all()
|
||||
today = date.today()
|
||||
manager_tryout_ids = [t.id for t in Tryout.query.filter_by(created_by=user.id).all()]
|
||||
stats['upcoming_matches'] = Match.query.filter(
|
||||
Match.tryout_id.in_(manager_tryout_ids),
|
||||
Match.status == 'scheduled',
|
||||
Match.date >= today
|
||||
).order_by(Match.date, Match.start_time).limit(5).all() if manager_tryout_ids else []
|
||||
|
||||
elif user.role == 'coach':
|
||||
stats['my_evaluations'] = Evaluation.query.filter_by(evaluator_id=user.id).count()
|
||||
@@ -67,54 +79,66 @@ def dashboard():
|
||||
evaluated_player_ids = [e.player_id for e in Evaluation.query.filter_by(evaluator_id=user.id).all()]
|
||||
stats['pending_evaluations'] = len(set(registered_player_ids) - set(evaluated_player_ids))
|
||||
stats['my_recent_evaluations'] = Evaluation.query.filter_by(evaluator_id=user.id).order_by(Evaluation.created_at.desc()).limit(10).all()
|
||||
today = date.today()
|
||||
org_team = OrgTeam.query.filter_by(coach_id=user.id).first()
|
||||
coach_tryout_ids = [t.id for t in Tryout.query.filter_by(target_org_team_id=org_team.id).all()] if org_team else []
|
||||
stats['upcoming_matches'] = Match.query.filter(
|
||||
Match.tryout_id.in_(coach_tryout_ids),
|
||||
Match.status == 'scheduled',
|
||||
Match.date >= today
|
||||
).order_by(Match.date, Match.start_time).limit(5).all() if coach_tryout_ids else []
|
||||
|
||||
elif user.role == 'player':
|
||||
stats['my_tryouts'] = TryoutRegistration.query.filter_by(player_id=user.id).count()
|
||||
stats['my_registrations'] = TryoutRegistration.query.filter_by(player_id=user.id).order_by(TryoutRegistration.registered_at.desc()).limit(5).all()
|
||||
|
||||
# Get next match for each tryout the player is in
|
||||
# Get upcoming matches for the player
|
||||
today = date.today()
|
||||
next_matches = []
|
||||
for reg in stats['my_registrations']:
|
||||
tryout = reg.tryout
|
||||
# Find matches where player participates (team membership or direct participant)
|
||||
player_teams = Team.query.join(TeamMember).filter(
|
||||
Team.tryout_id == tryout.id,
|
||||
TeamMember.player_id == user.id
|
||||
).all()
|
||||
|
||||
# Get all tryouts the player is registered for (not just the 5 most recent)
|
||||
all_registrations = TryoutRegistration.query.filter_by(player_id=user.id).all()
|
||||
registered_tryout_ids = [r.tryout_id for r in all_registrations]
|
||||
|
||||
# Get all matches where player is a participant (any match type)
|
||||
player_participant_matches = MatchParticipant.query.filter_by(player_id=user.id).all()
|
||||
player_match_ids = [p.match_id for p in player_participant_matches]
|
||||
|
||||
# Get all team memberships for this player
|
||||
player_team_memberships = TeamMember.query.filter_by(player_id=user.id).all()
|
||||
player_team_ids = [tm.team_id for tm in player_team_memberships]
|
||||
|
||||
# Find all scheduled matches in registered tryouts
|
||||
upcoming_matches = Match.query.filter(
|
||||
Match.tryout_id.in_(registered_tryout_ids),
|
||||
Match.status == 'scheduled',
|
||||
Match.date >= today
|
||||
).order_by(Match.date, Match.start_time).all()
|
||||
|
||||
for match in upcoming_matches:
|
||||
is_participant = False
|
||||
team = None
|
||||
|
||||
# Get matches for this tryout that include the player
|
||||
tryout_matches = Match.query.filter(
|
||||
Match.tryout_id == tryout.id,
|
||||
Match.status == 'scheduled'
|
||||
).order_by(Match.date, Match.start_time).all()
|
||||
if match.match_type == 'team_vs_team':
|
||||
# Check if player is on either team
|
||||
if match.team1_id in player_team_ids:
|
||||
is_participant = True
|
||||
team = next((tm for tm in player_team_memberships if tm.team_id == match.team1_id), None)
|
||||
elif match.team2_id in player_team_ids:
|
||||
is_participant = True
|
||||
team = next((tm for tm in player_team_memberships if tm.team_id == match.team2_id), None)
|
||||
else:
|
||||
# For player_vs_player and player_scrim, check MatchParticipant
|
||||
if match.id in player_match_ids:
|
||||
is_participant = True
|
||||
|
||||
for match in tryout_matches:
|
||||
# Check if player is in this match
|
||||
is_participant = False
|
||||
if match.match_type == 'team_vs_team':
|
||||
# Check if player is on team1 or team2
|
||||
if match.team1_id in [t.id for t in player_teams] or match.team2_id in [t.id for t in player_teams]:
|
||||
is_participant = True
|
||||
else:
|
||||
# Check if player is in match participants
|
||||
participant = MatchParticipant.query.filter_by(
|
||||
match_id=match.id,
|
||||
player_id=user.id
|
||||
).first()
|
||||
if participant:
|
||||
is_participant = True
|
||||
|
||||
if is_participant:
|
||||
# Check if match is upcoming
|
||||
match_date = match.date
|
||||
if match_date >= today:
|
||||
next_matches.append({
|
||||
'tryout': tryout,
|
||||
'match': match,
|
||||
'team': player_teams[0] if player_teams else None
|
||||
})
|
||||
break # Only get the next match per tryout
|
||||
if is_participant:
|
||||
tryout = match.tryout
|
||||
next_matches.append({
|
||||
'tryout': tryout,
|
||||
'match': match,
|
||||
'team': team.team if team else None
|
||||
})
|
||||
|
||||
stats['next_matches'] = next_matches
|
||||
|
||||
|
||||
+7
-7
@@ -309,13 +309,13 @@ def create_match(tryout_id):
|
||||
# Start time is now mandatory
|
||||
if not start_time_str:
|
||||
flash('Start time is required. Please select a time slot.', 'danger')
|
||||
return render_template('pages/create_match.html', tryout=tryout, teams=teams, all_players=all_players)
|
||||
return render_template('pages/match_form.html', tryout=tryout, teams=teams, all_players=all_players)
|
||||
|
||||
try:
|
||||
date_obj = datetime.strptime(date_str, '%Y-%m-%d').date() if date_str else tryout.date
|
||||
except (ValueError, TypeError):
|
||||
flash('Invalid date format.', 'danger')
|
||||
return render_template('pages/create_match.html', tryout=tryout, teams=teams, all_players=all_players)
|
||||
return render_template('pages/match_form.html', tryout=tryout, teams=teams, all_players=all_players)
|
||||
|
||||
start_time = None
|
||||
end_time = None
|
||||
@@ -331,7 +331,7 @@ def create_match(tryout_id):
|
||||
end_time = end_dt.time()
|
||||
except ValueError:
|
||||
flash('Invalid time format.', 'danger')
|
||||
return render_template('pages/create_match.html', tryout=tryout, teams=teams, all_players=all_players)
|
||||
return render_template('pages/match_form.html', tryout=tryout, teams=teams, all_players=all_players)
|
||||
|
||||
match = Match(
|
||||
tryout_id=tryout_id,
|
||||
@@ -425,7 +425,7 @@ def create_match(tryout_id):
|
||||
flash('Match scheduled successfully!', 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout_id))
|
||||
|
||||
return render_template('pages/create_match.html', tryout=tryout, teams=teams, all_players=all_players)
|
||||
return render_template('pages/match_form.html', tryout=tryout, teams=teams, all_players=all_players)
|
||||
|
||||
|
||||
@matches_bp.route('/<int:match_id>/edit', methods=['GET', 'POST'])
|
||||
@@ -472,12 +472,12 @@ def edit_match(match_id):
|
||||
match.date = datetime.strptime(date_str, '%Y-%m-%d').date()
|
||||
except (ValueError, TypeError):
|
||||
flash('Invalid date format.', 'danger')
|
||||
return render_template('pages/edit_match.html', match=match, tryout=tryout, teams=teams, all_players=all_players, current_player_ids=current_player_ids)
|
||||
return render_template('pages/match_form.html', match=match, tryout=tryout, teams=teams, all_players=all_players, current_player_ids=current_player_ids)
|
||||
|
||||
# Start time is now mandatory
|
||||
if not start_time_str:
|
||||
flash('Start time is required. Please select a time slot.', 'danger')
|
||||
return render_template('pages/edit_match.html', match=match, tryout=tryout, teams=teams, all_players=all_players, current_player_ids=current_player_ids)
|
||||
return render_template('pages/match_form.html', match=match, tryout=tryout, teams=teams, all_players=all_players, current_player_ids=current_player_ids)
|
||||
|
||||
try:
|
||||
match.start_time = datetime.strptime(start_time_str, '%H:%M').time()
|
||||
@@ -578,7 +578,7 @@ def edit_match(match_id):
|
||||
flash('Match updated successfully!', 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout.id))
|
||||
|
||||
return render_template('pages/edit_match.html', match=match, tryout=tryout, teams=teams, all_players=all_players, current_player_ids=current_player_ids, team1_player_ids=team1_player_ids, team2_player_ids=team2_player_ids)
|
||||
return render_template('pages/match_form.html', match=match, tryout=tryout, teams=teams, all_players=all_players, current_player_ids=current_player_ids, team1_player_ids=team1_player_ids, team2_player_ids=team2_player_ids)
|
||||
|
||||
|
||||
@matches_bp.route('/<int:match_id>/delete', methods=['POST'])
|
||||
|
||||
+17
-5
@@ -73,6 +73,8 @@ def create_tryout():
|
||||
return redirect(url_for('tryouts.list_tryouts'))
|
||||
|
||||
org_teams = OrgTeam.query.order_by(OrgTeam.name).all()
|
||||
managers = User.query.filter_by(role='manager', is_active_account=True).order_by(User.full_name).all()
|
||||
coaches = User.query.filter_by(role='coach', is_active_account=True).order_by(User.full_name).all()
|
||||
|
||||
if request.method == 'POST':
|
||||
title = request.form.get('title')
|
||||
@@ -82,12 +84,14 @@ def create_tryout():
|
||||
location = request.form.get('location')
|
||||
max_players = request.form.get('max_players')
|
||||
target_org_team_id = request.form.get('target_org_team_id')
|
||||
manager_id = request.form.get('manager_id')
|
||||
coach_id = request.form.get('coach_id')
|
||||
|
||||
try:
|
||||
date_obj = datetime.strptime(date_str, '%Y-%m-%d').date()
|
||||
except (ValueError, TypeError):
|
||||
flash('Invalid date format.', 'danger')
|
||||
return render_template('pages/create_tryout.html', org_teams=org_teams)
|
||||
return render_template('pages/tryout_form.html', tryout=None, org_teams=org_teams, managers=managers, coaches=coaches, esport_games=ESPORT_GAMES)
|
||||
|
||||
tryout = Tryout(
|
||||
title=title,
|
||||
@@ -98,14 +102,16 @@ def create_tryout():
|
||||
max_players=int(max_players) if max_players else None,
|
||||
created_by=current_user.id,
|
||||
status='upcoming',
|
||||
target_org_team_id=int(target_org_team_id) if target_org_team_id else None
|
||||
target_org_team_id=int(target_org_team_id) if target_org_team_id else None,
|
||||
manager_id=int(manager_id) if manager_id else None,
|
||||
coach_id=int(coach_id) if coach_id else None
|
||||
)
|
||||
db.session.add(tryout)
|
||||
db.session.commit()
|
||||
flash('Tryout created successfully!', 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout.id))
|
||||
|
||||
return render_template('pages/create_tryout.html', org_teams=org_teams, esport_games=ESPORT_GAMES)
|
||||
return render_template('pages/tryout_form.html', tryout=None, org_teams=org_teams, managers=managers, coaches=coaches, esport_games=ESPORT_GAMES)
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>/edit', methods=['GET', 'POST'])
|
||||
@@ -132,6 +138,8 @@ def edit_tryout(tryout_id):
|
||||
return redirect(url_for('tryouts.list_tryouts'))
|
||||
|
||||
org_teams = OrgTeam.query.order_by(OrgTeam.name).all()
|
||||
managers = User.query.filter_by(role='manager', is_active_account=True).order_by(User.full_name).all()
|
||||
coaches = User.query.filter_by(role='coach', is_active_account=True).order_by(User.full_name).all()
|
||||
|
||||
if request.method == 'POST':
|
||||
title = request.form.get('title')
|
||||
@@ -141,12 +149,14 @@ def edit_tryout(tryout_id):
|
||||
location = request.form.get('location')
|
||||
max_players = request.form.get('max_players')
|
||||
target_org_team_id = request.form.get('target_org_team_id')
|
||||
manager_id = request.form.get('manager_id')
|
||||
coach_id = request.form.get('coach_id')
|
||||
|
||||
try:
|
||||
date_obj = datetime.strptime(date_str, '%Y-%m-%d').date()
|
||||
except (ValueError, TypeError):
|
||||
flash('Invalid date format.', 'danger')
|
||||
return render_template('pages/edit_tryout.html', tryout=tryout, org_teams=org_teams, esport_games=ESPORT_GAMES)
|
||||
return render_template('pages/tryout_form.html', tryout=tryout, org_teams=org_teams, managers=managers, coaches=coaches, esport_games=ESPORT_GAMES)
|
||||
|
||||
tryout.title = title
|
||||
tryout.description = description
|
||||
@@ -155,11 +165,13 @@ def edit_tryout(tryout_id):
|
||||
tryout.location = location
|
||||
tryout.max_players = int(max_players) if max_players else None
|
||||
tryout.target_org_team_id = int(target_org_team_id) if target_org_team_id else None
|
||||
tryout.manager_id = int(manager_id) if manager_id else None
|
||||
tryout.coach_id = int(coach_id) if coach_id else None
|
||||
db.session.commit()
|
||||
flash('Tryout updated successfully!', 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout.id))
|
||||
|
||||
return render_template('pages/edit_tryout.html', tryout=tryout, org_teams=org_teams, esport_games=ESPORT_GAMES)
|
||||
return render_template('pages/tryout_form.html', tryout=tryout, org_teams=org_teams, managers=managers, coaches=coaches, esport_games=ESPORT_GAMES)
|
||||
|
||||
|
||||
@tryouts_bp.route('/<int:tryout_id>')
|
||||
|
||||
+9
-6
@@ -1433,12 +1433,13 @@ def add_personal_note():
|
||||
flash('Personal note added successfully!', 'success')
|
||||
return redirect(url_for('users.notes_dashboard'))
|
||||
|
||||
return render_template('pages/add_personal_note.html',
|
||||
return render_template('pages/add_note.html',
|
||||
players=players,
|
||||
matches=matches,
|
||||
tryouts=tryouts,
|
||||
teams=teams,
|
||||
org_team=org_team)
|
||||
org_team=org_team,
|
||||
context_type='general')
|
||||
|
||||
|
||||
@users_bp.route('/match/<int:match_id>/add-note', methods=['GET', 'POST'])
|
||||
@@ -1509,11 +1510,12 @@ def add_note_from_match(match_id):
|
||||
flash('Personal note added successfully!', 'success')
|
||||
return redirect(url_for('tryouts.view_tryout', tryout_id=tryout.id))
|
||||
|
||||
return render_template('pages/add_note_from_match.html',
|
||||
return render_template('pages/add_note.html',
|
||||
match=match,
|
||||
tryout=tryout,
|
||||
players=players,
|
||||
team_notes=team_notes)
|
||||
team_notes=team_notes,
|
||||
context_type='match')
|
||||
|
||||
|
||||
@users_bp.route('/tryout/<int:tryout_id>/add-note', methods=['GET', 'POST'])
|
||||
@@ -1583,8 +1585,9 @@ def add_note_from_tryout(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',
|
||||
return render_template('pages/add_note.html',
|
||||
tryout=tryout,
|
||||
players=players,
|
||||
team_notes=team_notes,
|
||||
preselected_player_id=preselected_player_id)
|
||||
preselected_player_id=preselected_player_id,
|
||||
context_type='tryout')
|
||||
|
||||
Reference in New Issue
Block a user