ajouté dark mode et changer l'affichage des équipes dans les match. Changé les couleurs pour ressembler plus au couleur de l'udes
This commit is contained in:
+48
-1
@@ -1,8 +1,9 @@
|
||||
from flask import Blueprint, render_template, redirect, url_for, flash
|
||||
from flask_login import login_required, current_user
|
||||
from extensions import db
|
||||
from models import User, Tryout, Evaluation, TryoutRegistration, Team, TeamMember
|
||||
from models import User, Tryout, Evaluation, TryoutRegistration, Team, TeamMember, Match, MatchParticipant
|
||||
from sqlalchemy import func
|
||||
from datetime import datetime, date
|
||||
|
||||
main_bp = Blueprint('main', __name__)
|
||||
|
||||
@@ -47,6 +48,52 @@ def dashboard():
|
||||
stats['average_score'] = db.session.query(func.avg(Evaluation.overall_score)).filter_by(player_id=user.id).scalar() or 0
|
||||
stats['my_registrations'] = TryoutRegistration.query.filter_by(player_id=user.id).order_by(TryoutRegistration.registered_at.desc()).limit(5).all()
|
||||
stats['my_eval_list'] = Evaluation.query.filter_by(player_id=user.id).order_by(Evaluation.created_at.desc()).limit(5).all()
|
||||
|
||||
# Get next match for each tryout the player is in
|
||||
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 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()
|
||||
|
||||
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
|
||||
|
||||
stats['next_matches'] = next_matches
|
||||
|
||||
elif user.role == 'scout':
|
||||
stats['total_players'] = User.query.filter_by(role='player').count()
|
||||
|
||||
Reference in New Issue
Block a user