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:
cedrick2711
2026-07-23 18:37:06 -04:00
parent f75c43ce1c
commit bf4c0ce4b1
22 changed files with 579 additions and 1287 deletions
+63 -39
View File
@@ -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