Files
paper-doc/backend/app/schemas/__init__.py
T
govin 06d7e922bd backend: add the paper authoring schema, API, and smoke test
A paper is a document written against a template. Its structure is never
copied into it: `paper` points at a template and the outline is read live on
every render, so switching `template_id` re-shapes the whole document in one
write.

Sentences are addressed by *position* rather than by a template row id:
`paper_sentence.paper_template_filed_sort` holds the sort of the placement the
sentence belongs to, and `sort` holds its place inside that paragraph. That
indirection is what makes a template switch non-destructive — a sentence that
remembers "position 7" lands on whatever the new template puts at position 7 —
and it is why a paragraph is any position either the template or the content
mentions: the structure survives with no content, and content whose position
the template does not define is still rendered, in order, under 未设定.

Citations are a table rather than a column, since one sentence may quote
several references. `quote` is required — a citation that does not say what it
quotes is refused with 422 — while `reference_id` is a plain nullable integer
with no foreign key, because the reference library does not exist yet.

Deleting a template a paper is written against is refused with 409 and a count,
matching how the field library refuses to drop a field still in use.

scripts/smoke_papers.py walks the whole loop — create, empty structure, write a
paragraph with citations, switch templates, keep unmatched positions, move a
paragraph, delete — in 40 checks, and cleans up after itself.
2026-09-18 17:29:12 +08:00

72 lines
1.5 KiB
Python

"""Pydantic schemas for request and response payloads."""
from app.schemas.common import (
BatchDeleteRequest,
BatchDeleteResult,
PageResult,
normalize_hex_color,
)
from app.schemas.paper import (
CitationInput,
CitationRead,
PaperCitationRead,
PaperCreate,
PaperDocumentRead,
PaperListItem,
PaperRead,
PaperStatus,
PaperUpdate,
ParagraphListRead,
ParagraphRead,
ParagraphUpdate,
SentenceCreate,
SentenceRead,
SentenceUpdate,
)
from app.schemas.paper_template import (
PaperTemplateCreate,
PaperTemplateListItem,
PaperTemplateRead,
PaperTemplateUpdate,
TemplateFieldInput,
TemplateFieldRead,
)
from app.schemas.section_field import (
SectionFieldCreate,
SectionFieldRead,
SectionFieldRef,
SectionFieldUpdate,
)
__all__ = [
"BatchDeleteRequest",
"CitationInput",
"CitationRead",
"PaperCitationRead",
"PaperCreate",
"PaperDocumentRead",
"PaperListItem",
"PaperRead",
"PaperStatus",
"PaperUpdate",
"ParagraphListRead",
"ParagraphRead",
"ParagraphUpdate",
"SentenceCreate",
"SentenceRead",
"SentenceUpdate",
"BatchDeleteResult",
"PageResult",
"PaperTemplateCreate",
"PaperTemplateListItem",
"PaperTemplateRead",
"PaperTemplateUpdate",
"SectionFieldCreate",
"SectionFieldRead",
"SectionFieldRef",
"SectionFieldUpdate",
"TemplateFieldInput",
"TemplateFieldRead",
"normalize_hex_color",
]