mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 05:09:58 -05:00
* Add Playlists: ordered, mixed-type collections A playlist (Collection kind='playlist') is a manually-curated, ordered list that mixes item types. Squash of the playlists feature branch (24 commits). Data model & API: - CollectionItem is polymorphic via item_kind: 'file' (FileGroup), 'zim' (zim_id + zim_entry), or 'url' (link to anything the WROLPi browser opens, e.g. /map?lat=&lon=&z=). CHECK constraint enforces exactly one kind; per-kind unique constraints; migration a7b1c2d3e4f5. - Endpoints: create playlist; add/remove/reorder items (idempotent adds: 201 new, 200 existing); GET returns the ordered items. All mutations wrol_mode_check'd. Config (source of truth): - playlists.yaml (PlaylistsConfig) stores each playlist's metadata AND ordered items (file by relative path, zim by path+entry, url inline); round-trips a DB wipe. Supports backup import (DB_CONFIG_FILE_NAMES). - The redundant generic CollectionsConfig (collections.yaml) is deleted: channels/domains own their configs, authors/subjects are re-derived. On-disk sync (sync_playlists_directory switch): - Each playlist materializes into the configurable Playlists Directory (playlists_destination, Settings UI input, excluded from indexing) with position-prefixed entries: NNNN_<file> hard links (copy fallback across filesystems) and NNNN_<title>.html stubs for zim/url items. - Tagged playlists are namespaced like channels: <playlists>/<tag>/<name>; a tag change moves the directory and prunes the empty old tag dir. - Deletion safety: managed files are only removed when they are our marked stubs or still have another hard link (st_nlink > 1) -- never a last copy. Stray loose files at the playlists root are removed; stub URLs are scheme-allowlisted (no javascript:/data:). Frontend: - /playlists list page (CollectionTable, name filter, New Playlist modal, Tag column) between Files and Zim in the nav. - View-only detail page (Name link) and edit page (Edit button): themed table with model icons/colors + poster thumbnails, items link to their model page (video/archive/doc) or preview, up/down reorder, remove, add-URL form, single-tag selector; all editing disabled in WROL Mode. - Reusable green "Add to Playlist" button on Video/Archive/Doc detail pages, the FilePreview toolbar, Zim search results, and Map pins (added as a /map URL item with a map-marker icon). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Playlist edit page parity: rename, custom directory, tag modal move suggestion Match the ChannelEditPage/DomainEditPage UX on the playlist edit page: Back/View buttons, an edit form (name, description, directory), and the shared CollectionTagModal with the violet "Tag" button. The tag modal now suggests moving the playlist to its managed tag location (playlists/<tag>/<name>); accepting the suggestion stores directory=None so the sync keeps auto-managing the location. Tag buttons on the Channel and Domain edit pages are now violet to match. Backend: update_collection learns rename (with per-kind validation and duplicate checks) and playlist custom directories (cleanup of the abandoned directory, config round-trip, commit-before-switch to avoid the background sync racing pre-commit state). tag_collection's duplicated untag/tag branches are merged, and the per-kind config-save dispatch is consolidated into _activate_config_save(). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Deduplicate Collection error handling and Tag creation Delete the duplicate UnknownCollection in wrolpi/collections/errors.py and re-export the canonical one from wrolpi/errors.py, which carries status_code=NOT_FOUND (the local copy inherited 500). Replace the repeated query/raise pattern in reorganize.py with Collection.find_by_id. Add Tag.get_or_create_tag and use it for collection tagging; flush the new Tag before returning so callers can read .id immediately -- previously tagging a collection with a brand-new tag name set tag_id=None. Regression test included. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
58 lines
2.9 KiB
Python
58 lines
2.9 KiB
Python
"""Make collection_item polymorphic: file | zim | url items.
|
|
|
|
CollectionItem previously only referenced a FileGroup. Playlists (kind='playlist') also need to
|
|
order Zim articles (zim_id + zim_entry, mirroring TagZimEntry) and arbitrary URLs (a link the WROLPi
|
|
browser can open, e.g. a map location). This adds item_kind plus the zim/url/title columns, relaxes
|
|
file_group_id to nullable, and adds per-kind unique constraints and a CHECK that exactly one kind's
|
|
columns are populated. Existing rows default to item_kind='file'.
|
|
|
|
Revision ID: a7b1c2d3e4f5
|
|
Revises: e6f7a8b9c0d1
|
|
Create Date: 2026-06-08
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision = 'a7b1c2d3e4f5'
|
|
down_revision = 'e6f7a8b9c0d1'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
CHECK_SQL = (
|
|
"(item_kind = 'file' AND file_group_id IS NOT NULL AND zim_id IS NULL AND url IS NULL)"
|
|
" OR (item_kind = 'zim' AND zim_id IS NOT NULL AND zim_entry IS NOT NULL"
|
|
" AND file_group_id IS NULL AND url IS NULL)"
|
|
" OR (item_kind = 'url' AND url IS NOT NULL AND file_group_id IS NULL AND zim_id IS NULL)"
|
|
)
|
|
|
|
|
|
def upgrade():
|
|
op.add_column('collection_item',
|
|
sa.Column('item_kind', sa.String(), nullable=False, server_default='file'))
|
|
op.add_column('collection_item', sa.Column('zim_id', sa.Integer(), nullable=True))
|
|
op.add_column('collection_item', sa.Column('zim_entry', sa.Text(), nullable=True))
|
|
op.add_column('collection_item', sa.Column('url', sa.Text(), nullable=True))
|
|
op.add_column('collection_item', sa.Column('title', sa.Text(), nullable=True))
|
|
# `file` is no longer the only kind, so a row need not have a FileGroup.
|
|
op.alter_column('collection_item', 'file_group_id', existing_type=sa.Integer(), nullable=True)
|
|
op.create_foreign_key('collection_item_zim_id_fkey', 'collection_item', 'zim',
|
|
['zim_id'], ['id'], ondelete='CASCADE')
|
|
op.create_unique_constraint('uq_collection_zim_entry', 'collection_item',
|
|
['collection_id', 'zim_id', 'zim_entry'])
|
|
op.create_unique_constraint('uq_collection_url', 'collection_item', ['collection_id', 'url'])
|
|
op.create_check_constraint('ck_collection_item_kind', 'collection_item', CHECK_SQL)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_constraint('ck_collection_item_kind', 'collection_item', type_='check')
|
|
op.drop_constraint('uq_collection_url', 'collection_item', type_='unique')
|
|
op.drop_constraint('uq_collection_zim_entry', 'collection_item', type_='unique')
|
|
op.drop_constraint('collection_item_zim_id_fkey', 'collection_item', type_='foreignkey')
|
|
# Restore NOT NULL (valid only if no non-file rows remain).
|
|
op.alter_column('collection_item', 'file_group_id', existing_type=sa.Integer(), nullable=False)
|
|
op.drop_column('collection_item', 'title')
|
|
op.drop_column('collection_item', 'url')
|
|
op.drop_column('collection_item', 'zim_entry')
|
|
op.drop_column('collection_item', 'zim_id')
|
|
op.drop_column('collection_item', 'item_kind')
|