59746d213d
Reframe a series from "ordered chapters that own pages" to ONE flat, series-global ordered run of pages with optional cosmetic chapter DIVIDERS over it. A chapter no longer wraps content — it's a labeled divider anchored to the page that begins it; a page's chapter is derived as the nearest preceding divider. This is what lets installments assembled from multiple sources sit in one continuous, correctly-numbered sequence (operator's Goblin Juice case). - migration 0047: flatten each series to a series-global page_number (preserving today's reading order); convert each existing chapter to a divider anchored at its first page (keeping title/stated_part); drop series_page.chapter_id; reshape series_chapter (anchor_page_id UNIQUE FK, drop chapter_number/is_placeholder/stated_page_start/end). Loss-safe for content; drops empty placeholder chapters + a redundant page-1 divider. - series_page: page_number is now the series-global order; no chapter_id. - series_chapter: anchored divider (anchor_page_id, title, stated_part). - series_service: flat list_pages (one run + derived dividers + per-page source_post + part_gaps), series-wide reorder/renumber, divider CRUD (create/update/move/delete); retired per-chapter reorder/merge/placement. - api/tags: drop chapter_id from add; /chapters endpoints are divider create/update/delete (removed chapter reorder/merge/page-reorder). - series_match_service: series "end" reads max(series_page.stated_page); accept appends via add_post. tag_service series-merge appends src's pages after tgt's max so the merged series stays one clean run. - frontend: seriesManage store + SeriesManageView → one continuous drag-reorder grid with inline divider bars + series-global page numbers; reader walks the flat run, headings from dividers; PostSeriesMenu copy. - tests reworked across the series suite for the divider model. Phase 2 (pending staging for add-from-post) is separate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
"""SeriesChapter — a cosmetic chapter DIVIDER within a series (FC-6.x reframe).
|
|
|
|
A series is ONE flat, series-global ordered run of SeriesPages. A chapter is NOT
|
|
a container — it owns no pages. It is a labeled divider anchored to the page that
|
|
BEGINS the chapter (anchor_page_id → series_page): "a new chapter starts here."
|
|
A page's chapter is derived at read time as the nearest preceding divider.
|
|
|
|
Dividers never affect page ordering or the series-global page numbers; they stay
|
|
pinned to their anchor page across reorders. anchor_page_id is UNIQUE — at most
|
|
one chapter begins at a given page — and FK-cascades, so removing the anchor page
|
|
from the series drops the divider (the chapter merges into the preceding run).
|
|
|
|
title is the optional chapter name; stated_part is the optional operator-facing
|
|
"Part N" label (shown instead of a derived ordinal when set).
|
|
"""
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, Integer, Text, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from .base import Base
|
|
|
|
|
|
class SeriesChapter(Base):
|
|
__tablename__ = "series_chapter"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
series_tag_id: Mapped[int] = mapped_column(
|
|
ForeignKey("tag.id", ondelete="CASCADE"), nullable=False, index=True
|
|
)
|
|
anchor_page_id: Mapped[int] = mapped_column(
|
|
ForeignKey("series_page.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
unique=True,
|
|
)
|
|
title: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
stated_part: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), nullable=False, server_default=func.now()
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
nullable=False,
|
|
server_default=func.now(),
|
|
onupdate=func.now(),
|
|
)
|