Replace emoji icons with local SVG files for consistent rendering
- Created 10 SVG icon files in app/static/icons/ (Feather Icons style) - Updated base.html with SVG icons in navigation and dark mode toggle - Updated dashboard.html with icons in stats cards and quick actions - Updated content_list_new.html (playlist management) with SVG icons - Updated upload_media.html with upload-related icons - Updated manage_player.html with player management icons - Icons use currentColor for automatic theme adaptation - Removed emoji dependency for better Raspberry Pi compatibility - Added ICON_INTEGRATION.md documentation
This commit is contained in:
97
app/models/playlist.py
Normal file
97
app/models/playlist.py
Normal file
@@ -0,0 +1,97 @@
|
||||
"""Playlist model for managing content collections."""
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from app.extensions import db
|
||||
|
||||
|
||||
# Association table for many-to-many relationship between playlists and content
|
||||
playlist_content = db.Table('playlist_content',
|
||||
db.Column('playlist_id', db.Integer, db.ForeignKey('playlist.id', ondelete='CASCADE'), primary_key=True),
|
||||
db.Column('content_id', db.Integer, db.ForeignKey('content.id', ondelete='CASCADE'), primary_key=True),
|
||||
db.Column('position', db.Integer, default=0),
|
||||
db.Column('duration', db.Integer, default=10)
|
||||
)
|
||||
|
||||
|
||||
class Playlist(db.Model):
|
||||
"""Playlist model representing a collection of content.
|
||||
|
||||
Attributes:
|
||||
id: Primary key
|
||||
name: Unique playlist name
|
||||
description: Optional playlist description
|
||||
version: Version number for synchronization
|
||||
is_active: Whether playlist is active
|
||||
created_at: Playlist creation timestamp
|
||||
updated_at: Last modification timestamp
|
||||
"""
|
||||
__tablename__ = 'playlist'
|
||||
|
||||
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)
|
||||
orientation = db.Column(db.String(20), default='Landscape', nullable=False)
|
||||
version = db.Column(db.Integer, default=1, nullable=False)
|
||||
is_active = db.Column(db.Boolean, default=True, nullable=False)
|
||||
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='playlist', lazy='dynamic')
|
||||
contents = db.relationship('Content', secondary=playlist_content,
|
||||
back_populates='playlists', lazy='dynamic')
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""String representation of Playlist."""
|
||||
return f'<Playlist {self.name} (ID={self.id}, Version={self.version})>'
|
||||
|
||||
@property
|
||||
def player_count(self) -> int:
|
||||
"""Get number of players assigned to this playlist."""
|
||||
return self.players.count()
|
||||
|
||||
@property
|
||||
def content_count(self) -> int:
|
||||
"""Get number of content items in this playlist."""
|
||||
return self.contents.count()
|
||||
|
||||
@property
|
||||
def total_duration(self) -> int:
|
||||
"""Calculate total duration of all content in seconds."""
|
||||
total = 0
|
||||
for content in self.contents:
|
||||
total += content.duration or 10
|
||||
return total
|
||||
|
||||
def increment_version(self) -> None:
|
||||
"""Increment playlist version for sync detection."""
|
||||
self.version += 1
|
||||
self.updated_at = datetime.utcnow()
|
||||
|
||||
def get_content_ordered(self) -> List:
|
||||
"""Get content items ordered by position."""
|
||||
# Query through association table to get position
|
||||
from sqlalchemy import select
|
||||
stmt = select(playlist_content.c.content_id,
|
||||
playlist_content.c.position,
|
||||
playlist_content.c.duration).where(
|
||||
playlist_content.c.playlist_id == self.id
|
||||
).order_by(playlist_content.c.position)
|
||||
|
||||
results = db.session.execute(stmt).fetchall()
|
||||
|
||||
ordered_content = []
|
||||
for row in results:
|
||||
content = db.session.get(Content, row.content_id)
|
||||
if content:
|
||||
content._playlist_position = row.position
|
||||
content._playlist_duration = row.duration
|
||||
ordered_content.append(content)
|
||||
|
||||
return ordered_content
|
||||
|
||||
|
||||
# Import Content here to avoid circular import
|
||||
from app.models.content import Content
|
||||
Reference in New Issue
Block a user