Backend: - PdfTemplate model with locale field + UNIQUE(name, locale) constraint - Migration 007: pdf_templates table + template_id FK on generated_pdfs - Template service: CRUD, Jinja2 validation, render preview with sample data - Admin endpoints: CRUD /admin/pdf-templates + POST preview - User endpoint: GET /pdf/templates (active templates list) - pdf_service: resolves template from DB by ID or falls back to default for the appropriate locale - AI generate_pdf tool accepts optional template_id - Seed script + 4 HTML template files: - Basic Report (en/ru) — general-purpose report - Medical Report (en/ru) — health-focused with disclaimers Frontend: - Admin PDF templates page with editor, locale selector, live preview (iframe), template variables reference panel - PDF page: template selector dropdown in generation form - API clients for admin CRUD + user template listing - Sidebar: admin templates link - English + Russian translations Also added Phase 9 (OAuth) and Phase 10 (Rate Limits) placeholders to GeneralPlan. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""Create pdf_templates table with locale support, seed defaults, add template_id to generated_pdfs
|
|
|
|
Revision ID: 007
|
|
Revises: 006
|
|
Create Date: 2026-03-19
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
|
|
revision: str = "007"
|
|
down_revision: Union[str, None] = "006"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"pdf_templates",
|
|
sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
|
sa.Column("name", sa.String(100), nullable=False),
|
|
sa.Column("locale", sa.String(10), nullable=False, server_default="en"),
|
|
sa.Column("description", sa.Text, nullable=True),
|
|
sa.Column("html_content", sa.Text, nullable=False),
|
|
sa.Column("is_default", sa.Boolean, nullable=False, server_default=sa.text("false")),
|
|
sa.Column("is_active", sa.Boolean, nullable=False, server_default=sa.text("true")),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.UniqueConstraint("name", "locale", name="uq_pdf_templates_name_locale"),
|
|
)
|
|
|
|
op.add_column("generated_pdfs", sa.Column(
|
|
"template_id", UUID(as_uuid=True),
|
|
sa.ForeignKey("pdf_templates.id", ondelete="SET NULL"), nullable=True,
|
|
))
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_column("generated_pdfs", "template_id")
|
|
op.drop_table("pdf_templates")
|