updated first commit
This commit is contained in:
54
app/models/player.py
Normal file
54
app/models/player.py
Normal file
@@ -0,0 +1,54 @@
|
||||
"""
|
||||
Player model for digital signage displays
|
||||
"""
|
||||
|
||||
from app.extensions import db, bcrypt
|
||||
|
||||
class Player(db.Model):
|
||||
"""Player model representing digital signage displays"""
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
username = db.Column(db.String(255), nullable=False, index=True)
|
||||
hostname = db.Column(db.String(255), nullable=False, unique=True, index=True)
|
||||
password = db.Column(db.String(255), nullable=False)
|
||||
quickconnect_password = db.Column(db.String(255), nullable=True)
|
||||
playlist_version = db.Column(db.Integer, default=1)
|
||||
locked_to_group_id = db.Column(db.Integer, db.ForeignKey('group.id'), nullable=True)
|
||||
created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
|
||||
last_seen = db.Column(db.DateTime)
|
||||
is_active = db.Column(db.Boolean, default=True)
|
||||
|
||||
# Relationships
|
||||
content = db.relationship('Content', backref='player', lazy=True, cascade='all, delete-orphan')
|
||||
locked_to_group = db.relationship('Group', foreign_keys=[locked_to_group_id], backref='locked_players')
|
||||
|
||||
def set_password(self, password):
|
||||
"""Hash and set player password"""
|
||||
self.password = bcrypt.generate_password_hash(password).decode('utf-8')
|
||||
|
||||
def check_password(self, password):
|
||||
"""Check if provided password matches player's password"""
|
||||
return bcrypt.check_password_hash(self.password, password)
|
||||
|
||||
def set_quickconnect_password(self, password):
|
||||
"""Hash and set quickconnect password"""
|
||||
self.quickconnect_password = bcrypt.generate_password_hash(password).decode('utf-8')
|
||||
|
||||
def verify_quickconnect_code(self, code):
|
||||
"""Verify quickconnect code"""
|
||||
if not self.quickconnect_password:
|
||||
return False
|
||||
return bcrypt.check_password_hash(self.quickconnect_password, code)
|
||||
|
||||
def increment_playlist_version(self):
|
||||
"""Increment playlist version to notify clients of changes"""
|
||||
self.playlist_version += 1
|
||||
db.session.commit()
|
||||
|
||||
@property
|
||||
def is_locked_to_group(self):
|
||||
"""Check if player is locked to a group"""
|
||||
return self.locked_to_group_id is not None
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Player {self.username} ({self.hostname})>'
|
||||
Reference in New Issue
Block a user