régler problème avec les liens TRN
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from extensions import db, login_manager
|
||||
from flask_login import UserMixin
|
||||
from datetime import datetime
|
||||
from urllib.parse import quote
|
||||
|
||||
ROLES = ['president', 'manager', 'coach', 'player', 'scout']
|
||||
|
||||
@@ -35,7 +36,6 @@ class User(UserMixin, db.Model):
|
||||
|
||||
# E-Sports specific fields
|
||||
games = db.Column(db.Text, nullable=True) # Comma-separated list of games
|
||||
trn_username = db.Column(db.String(120), nullable=True) # Tracker Network username
|
||||
discord_username = db.Column(db.String(100), nullable=True) # Discord handle
|
||||
league_os_profile = db.Column(db.String(255), nullable=True) # League OS profile URL or ID
|
||||
|
||||
@@ -90,12 +90,97 @@ class User(UserMixin, db.Model):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_gamertags(self):
|
||||
"""Return gamertags as a dict keyed by game."""
|
||||
return {gt.game: {'gamertag': gt.gamertag, 'platform': gt.platform} for gt in self.gamertags}
|
||||
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(user_id):
|
||||
return User.query.get(int(user_id))
|
||||
|
||||
|
||||
# Platform options for games that require platform specification
|
||||
GAME_PLATFORMS = {
|
||||
'Valorant': [], # No platform needed
|
||||
'League of Legends': [],
|
||||
'Counter-Strike 2': [],
|
||||
'Apex Legends': ['PC', 'PlayStation', 'Xbox', 'Nintendo Switch'],
|
||||
'Overwatch 2': ['PC', 'PlayStation', 'Xbox', 'Nintendo Switch'],
|
||||
'Rainbow Six Siege': ['Ubisoft', 'PlayStation', 'Xbox'], # Ubisoft = Uplay/Steam
|
||||
'Fortnite': ['PC', 'PlayStation', 'Xbox', 'Nintendo Switch', 'Mobile'],
|
||||
'Rocket League': ['Epic', 'PlayStation', 'Xbox', 'Nintendo Switch'], # Epic uses EpicID, others use username
|
||||
'Call of Duty': ['PC', 'PlayStation', 'Xbox'],
|
||||
'Dota 2': [],
|
||||
'Super Smash Bros.': ['Nintendo Switch'],
|
||||
'Street Fighter 6': ['PC', 'PlayStation', 'Xbox'],
|
||||
}
|
||||
|
||||
|
||||
# Platform code mapping for TRN URLs (platform -> TRN code)
|
||||
PLATFORM_CODES = {
|
||||
'Ubisoft': 'ubi',
|
||||
'PlayStation': 'psn',
|
||||
'Xbox': 'xbl',
|
||||
'Nintendo Switch': 'switch',
|
||||
'PC': 'pc',
|
||||
'Mobile': 'mobile',
|
||||
'Steam': 'steam',
|
||||
'Epic': 'epic',
|
||||
}
|
||||
|
||||
# TRN URL mapping for each game
|
||||
TRN_URLS = {
|
||||
'Valorant': 'https://tracker.gg/valorant/profile/riot/{username}',
|
||||
'League of Legends': 'https://tracker.gg/lol/profile/{username}',
|
||||
'Counter-Strike 2': 'https://tracker.gg/cs2/profile/steam/{username}',
|
||||
'Apex Legends': 'https://tracker.gg/apex/profile/{platform}/{username}',
|
||||
'Overwatch 2': 'https://tracker.gg/overwatch/profile/{platform}/{username}',
|
||||
'Rainbow Six Siege': 'https://r6.tracker.network/r6siege/profile/{platform_code}/{username}',
|
||||
'Fortnite': 'https://tracker.gg/fortnite/profile/{platform}/{username}',
|
||||
'Rocket League': 'https://rocketleague.tracker.network/rocket-league/profile/{platform_code}/{username}',
|
||||
'Call of Duty': 'https://tracker.gg/call-of-duty/profile/{platform}/{username}',
|
||||
'Dota 2': 'https://tracker.gg/dota2/profile/steam/{username}',
|
||||
'Super Smash Bros.': 'https://tracker.gg/smash/profile/{username}',
|
||||
'Street Fighter 6': 'https://tracker.gg/streetfighter/profile/{username}',
|
||||
}
|
||||
|
||||
|
||||
class UserGamertag(db.Model):
|
||||
"""Store gamertag per game for each user."""
|
||||
__tablename__ = 'user_gamertags'
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
||||
game = db.Column(db.String(50), nullable=False)
|
||||
gamertag = db.Column(db.String(120), nullable=False)
|
||||
platform = db.Column(db.String(30), nullable=True) # For games that need platform (e.g., PSN, Xbox Live)
|
||||
|
||||
user = db.relationship('User', backref='gamertags')
|
||||
|
||||
__table_args__ = (
|
||||
db.UniqueConstraint('user_id', 'game', name='unique_user_game'),
|
||||
)
|
||||
|
||||
def get_trn_url(self):
|
||||
"""Generate the TRN URL for this gamertag."""
|
||||
if self.game not in TRN_URLS:
|
||||
return None
|
||||
|
||||
url = TRN_URLS[self.game]
|
||||
# URL-encode the gamertag to handle special characters like #, spaces, etc.
|
||||
encoded_gamertag = quote(self.gamertag, safe='')
|
||||
|
||||
# Check for platform_code placeholder (used for R6 and Rocket League)
|
||||
if '{platform_code}' in url and '{username}' in url:
|
||||
platform_code = PLATFORM_CODES.get(self.platform, self.platform.lower().replace(' ', '-')) if self.platform else ''
|
||||
return url.format(platform_code=platform_code, username=encoded_gamertag)
|
||||
elif '{platform}' in url and '{username}' in url:
|
||||
return url.format(platform=self.platform.lower().replace(' ', '-'), username=encoded_gamertag)
|
||||
elif '{username}' in url:
|
||||
return url.format(username=encoded_gamertag)
|
||||
return url
|
||||
|
||||
|
||||
class OrgTeam(db.Model):
|
||||
"""Persistent organization teams (e.g., Varsity, JV) that exist across tryouts."""
|
||||
__tablename__ = 'org_teams'
|
||||
|
||||
Reference in New Issue
Block a user