Models (6 + 1 association table): - User: Authentication with bcrypt, admin role check, last_login tracking - Player: Digital signage devices with auth codes, status tracking, online detection - Group: Player/content organization with statistics properties - Content: Media files with type detection, file size helpers, position ordering - ServerLog: Audit trail with class methods for logging levels - PlayerFeedback: Player status updates with error tracking - group_content: Many-to-many association table for groups and content Model improvements: - Added type hints to all methods and properties - Added database indexes on frequently queried columns (username, auth_code, group_id, player_id, position, level, timestamp, status) - Added comprehensive docstrings - Added helper properties (is_online, is_admin, file_size_mb, etc.) - Added relationship back_populates for bidirectional navigation - Added timestamps (created_at, updated_at, last_seen, uploaded_at) Utils (4 modules): - logger.py: Logging utility with level-based functions (info, warning, error) - uploads.py: File upload handling with progress tracking, video optimization - group_player_management.py: Player/group status tracking and bulk operations - pptx_converter.py: PowerPoint to PDF conversion using LibreOffice Utils improvements: - Full type hints on all functions - Comprehensive error handling - Progress tracking for long-running operations - Video optimization (H.264, 30fps, max 1080p, 8Mbps) - Helper functions for time formatting and statistics - Proper logging of all operations Performance optimizations: - Database indexes on all foreign keys and frequently filtered columns - Lazy loading for relationships where appropriate - Efficient queries with proper ordering - Helper properties to avoid repeated calculations Ready for template migration and testing
71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
"""Group model for organizing players and content."""
|
|
from datetime import datetime
|
|
from typing import List, Optional
|
|
|
|
from app.extensions import db
|
|
|
|
|
|
# Association table for many-to-many relationship between groups and content
|
|
group_content = db.Table('group_content',
|
|
db.Column('group_id', db.Integer, db.ForeignKey('group.id'), primary_key=True),
|
|
db.Column('content_id', db.Integer, db.ForeignKey('content.id'), primary_key=True)
|
|
)
|
|
|
|
|
|
class Group(db.Model):
|
|
"""Group model for organizing players with shared content.
|
|
|
|
Attributes:
|
|
id: Primary key
|
|
name: Unique group name
|
|
description: Optional group description
|
|
created_at: Group creation timestamp
|
|
updated_at: Last modification timestamp
|
|
"""
|
|
__tablename__ = 'group'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
name = db.Column(db.String(100), nullable=False, unique=True, index=True)
|
|
description = db.Column(db.Text, nullable=True)
|
|
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at = db.Column(db.DateTime, default=datetime.utcnow,
|
|
onupdate=datetime.utcnow, nullable=False)
|
|
|
|
# Relationships
|
|
players = db.relationship('Player', back_populates='group', lazy='dynamic')
|
|
contents = db.relationship('Content', secondary=group_content,
|
|
back_populates='groups', lazy='dynamic')
|
|
|
|
def __repr__(self) -> str:
|
|
"""String representation of Group."""
|
|
return f'<Group {self.name} (ID={self.id})>'
|
|
|
|
@property
|
|
def player_count(self) -> int:
|
|
"""Get number of players in this group."""
|
|
return self.players.count()
|
|
|
|
@property
|
|
def content_count(self) -> int:
|
|
"""Get number of content items in this group."""
|
|
return self.contents.count()
|
|
|
|
def add_player(self, player) -> None:
|
|
"""Add a player to this group.
|
|
|
|
Args:
|
|
player: Player instance to add
|
|
"""
|
|
player.group_id = self.id
|
|
self.updated_at = datetime.utcnow()
|
|
|
|
def remove_player(self, player) -> None:
|
|
"""Remove a player from this group.
|
|
|
|
Args:
|
|
player: Player instance to remove
|
|
"""
|
|
if player.group_id == self.id:
|
|
player.group_id = None
|
|
self.updated_at = datetime.utcnow()
|