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:
cedrick2711
2026-07-20 17:41:22 -04:00
parent 027e529885
commit 346229778f
18 changed files with 343 additions and 69 deletions
+58 -4
View File
@@ -65,7 +65,6 @@ class User(UserMixin, db.Model):
full_name: User's display name.
email: User's email address.
phone: Optional phone number.
team_id: Foreign key to the user's organization team.
is_active_account: Whether the account is active.
games: Comma-separated list of games the user plays.
discord_username: User's Discord handle.
@@ -79,7 +78,6 @@ class User(UserMixin, db.Model):
full_name = db.Column(db.String(100), nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
phone = db.Column(db.String(20), nullable=True)
team_id = db.Column(db.Integer, db.ForeignKey('org_teams.id'), nullable=True)
is_active_account = db.Column(db.Boolean, default=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
@@ -205,6 +203,14 @@ class User(UserMixin, db.Model):
"""
return {gt.game: {'gamertag': gt.gamertag, 'platform': gt.platform} for gt in self.gamertags}
def get_org_teams(self):
"""Return all organization teams this player belongs to.
Returns:
list: List of OrgTeam objects the player is assigned to.
"""
return [tp.org_team for tp in self.team_placements]
# Platform options for games that require platform specification
GAME_PLATFORMS = {
@@ -296,6 +302,35 @@ class UserGamertag(db.Model):
return url
class TeamPlayer(db.Model):
"""Many-to-many relationship between players and organization teams.
Allows a player to be in multiple teams with a status of starter or substitute.
Attributes:
id: Unique identifier.
player_id: Foreign key to the player.
org_team_id: Foreign key to the organization team.
status: Player status on the team ('starter' or 'substitute').
position: Player's position on the team (optional).
added_at: Timestamp when player was added.
"""
__tablename__ = 'team_players'
id = db.Column(db.Integer, primary_key=True)
player_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
org_team_id = db.Column(db.Integer, db.ForeignKey('org_teams.id'), nullable=False)
status = db.Column(db.String(20), nullable=False, default='starter') # 'starter' or 'substitute'
position = db.Column(db.String(50), nullable=True)
added_at = db.Column(db.DateTime, default=datetime.utcnow)
player = db.relationship('User', foreign_keys=[player_id], backref='team_placements')
org_team = db.relationship('OrgTeam', foreign_keys=[org_team_id], backref='team_players')
__table_args__ = (
db.UniqueConstraint('player_id', 'org_team_id', name='unique_player_org_team'),
)
class OrgTeam(db.Model):
"""Persistent organization teams (e.g., Varsity, JV) that exist across tryouts.
@@ -306,6 +341,7 @@ class OrgTeam(db.Model):
id: Unique identifier.
name: Team name (e.g., "Varsity", "Junior Varsity").
coach_id: Foreign key to the assigned coach.
manager_id: Foreign key to the assigned manager.
created_by: Foreign key to the user who created the team.
created_at: Timestamp of team creation.
"""
@@ -313,12 +349,30 @@ class OrgTeam(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False, unique=True)
coach_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True)
manager_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True)
created_by = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
coach = db.relationship('User', foreign_keys=[coach_id], backref='coached_org_team', uselist=False)
manager = db.relationship('User', foreign_keys=[manager_id], backref='managed_org_team', uselist=False)
creator = db.relationship('User', foreign_keys=[created_by])
players = db.relationship('User', foreign_keys='User.team_id', backref='org_team', lazy='dynamic')
@property
def players(self):
"""Get all players assigned to this team.
Returns:
list: List of User objects assigned to this team.
"""
return [tp.player for tp in self.team_players]
def get_players_with_status(self):
"""Get all players with their status on this team.
Returns:
list: List of dicts with 'player' and 'status' keys.
"""
return [{'player': tp.player, 'status': tp.status, 'position': tp.position} for tp in self.team_players]
class Tryout(db.Model):
@@ -645,7 +699,7 @@ class Contract(db.Model):
# Manager can view contracts for players on their teams
if user.role == 'manager':
player = User.query.get(self.player_id)
if player and player.team_id:
if player and player.get_org_teams():
return True
# Coach can view contracts for players on their team
if user.role == 'coach':