class Tournament(db.Model): __tablename__ = 'tournaments' id = db.Column(db.Integer, primary_key=True) creator = db.Column(db.Integer, db.ForeignKey('users.id')) hashid = db.Column(db.String(10), unique=True) name = db.Column(db.String(50), nullable=False) public = db.Column(db.Boolean, default=False) registration_open = db.Column(db.Boolean, default=True) description = db.Column(db.String(1000)) external_url = db.Column(db.String(120)) start_timestamp = db.Column(db.DateTime) creation_timestamp = db.Column(db.DateTime, default=datetime.utcnow()) api_key = db.Column(db.String(16), default=None) players = db.relationship( 'User', secondary=tournament_players_association_table, lazy=True, backref=db.backref('tournaments', lazy=True), ) banned_players = db.relationship( 'User', secondary=tournament_banned_players_association_table, lazy=True, backref=db.backref('tournaments_banned', lazy=True), ) def __init__(self, **kwargs): super(Tournament, self).__init__(**kwargs) self.hashid = secrets.token_urlsafe(8)[:8] self.api_key = secrets.token_urlsafe(16)[:16]
class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) alternative_id = db.Column(db.Integer, index=True, unique=True) username = db.Column(db.String(25), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password = db.Column(db.String(128)) active = db.Column(db.Boolean) avatar = db.Column(db.String(15), default=None) last_seen = db.Column(db.DateTime, default=datetime.utcnow()) last_seen_ingame = db.Column(db.DateTime, default=datetime.utcnow()) is_online = db.Column(db.Boolean, default=False) active_sessions = db.Column(db.Integer, default=0) status = db.Column(db.String(15), default='online') caller = db.Column(db.String(20), default='default') cpu_delay = db.Column(db.Integer, default=0) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) registration_timestamp = db.Column(db.DateTime, default=datetime.utcnow()) requested_friend_reqs = db.relationship( 'FriendshipRequest', foreign_keys='FriendshipRequest.requesting_user_id', backref='requesting_user' ) received_friend_reqs = db.relationship( 'FriendshipRequest', foreign_keys='FriendshipRequest.receiving_user_id', backref='receiving_user' ) aspiring_friends = association_proxy('received_friend_reqs', 'requesting_user') desired_friends = association_proxy('requested_friend_reqs', 'receiving_user') requested_friend_confs = db.relationship( 'Friendship', foreign_keys='Friendship.user1_id', backref='requesting_friend' ) received_friend_confs = db.relationship( 'Friendship', foreign_keys='Friendship.user2_id', backref='receiving_friend' ) friends_requested = association_proxy('received_friend_confs', 'requesting_friend') friends_received = association_proxy('requested_friend_confs', 'receiving_friend') def __init__(self, **kwargs): super(User, self).__init__(**kwargs) self.alternative_id = self.id def __repr__(self): return '<User {}>'.format(self.username) def as_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns} def recently_online(self): return self.is_online or self.last_seen > datetime.utcnow() - timedelta(minutes=1)
class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(25), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password = db.Column(db.String(128)) active = db.Column(db.Boolean) avatar = db.Column(db.String(15), default=None) last_seen = db.Column(db.DateTime, default=datetime.utcnow) last_seen_ingame = db.Column(db.DateTime, default=datetime.utcnow) is_online = db.Column(db.Boolean, default=False) active_sessions = db.Column(db.Integer, default=0) status = db.Column(db.String(15), default='online') caller = db.Column(db.String(20), default='default') cpu_delay = db.Column(db.Integer, default=0) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) requested_friend_reqs = db.relationship( 'FriendshipRequest', foreign_keys='FriendshipRequest.requesting_user_id', backref='requesting_user') received_friend_reqs = db.relationship( 'FriendshipRequest', foreign_keys='FriendshipRequest.receiving_user_id', backref='receiving_user') aspiring_friends = association_proxy('received_friend_reqs', 'requesting_user') desired_friends = association_proxy('requested_friend_reqs', 'receiving_user') requested_friend_confs = db.relationship( 'Friendship', foreign_keys='Friendship.user1_id', backref='requesting_friend') received_friend_confs = db.relationship('Friendship', foreign_keys='Friendship.user2_id', backref='receiving_friend') friends_requested = association_proxy('received_friend_confs', 'requesting_friend') friends_received = association_proxy('requested_friend_confs', 'receiving_friend') # used to save the settings of a user during a game (e.g. hide statistics) # ingame_settings ingame_keypad_visibility = db.Column(db.Boolean, default=True) # keypad_position -> 0:default ; 1:full screen ingame_keypad_position = db.Column(db.Integer, default=0) ingame_statistics_visibility = db.Column(db.Boolean, default=True) # streamoverlay -> False:normal theme ; True:streamoverlay ingame_streamoverlay = db.Column(db.Boolean, default=False) ingame_caller_mute = db.Column(db.Boolean, default=False) def __repr__(self): return '<User {}>'.format(self.username) def as_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns} def ping(self): self.last_seen = datetime.utcnow() last_online = self.is_online self.is_online = True db.session.commit() return last_online != self.is_online def recently_online(self): return self.is_online or self.last_seen > datetime.utcnow( ) - timedelta(minutes=1)