Phase 8: Customizable PDF Templates — locale support, admin editor, seed templates
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>
This commit is contained in:
@@ -9,8 +9,9 @@ from app.models.memory_entry import MemoryEntry
|
||||
from app.models.notification import Notification
|
||||
from app.models.setting import Setting
|
||||
from app.models.generated_pdf import GeneratedPdf
|
||||
from app.models.pdf_template import PdfTemplate
|
||||
|
||||
__all__ = [
|
||||
"User", "Session", "Chat", "Message", "ContextFile", "Skill",
|
||||
"Document", "MemoryEntry", "Notification", "Setting", "GeneratedPdf",
|
||||
"Document", "MemoryEntry", "Notification", "Setting", "GeneratedPdf", "PdfTemplate",
|
||||
]
|
||||
|
||||
@@ -20,4 +20,9 @@ class GeneratedPdf(Base):
|
||||
UUID(as_uuid=True), ForeignKey("chats.id", ondelete="SET NULL"), nullable=True
|
||||
)
|
||||
|
||||
template_id: Mapped[uuid.UUID | None] = mapped_column(
|
||||
UUID(as_uuid=True), ForeignKey("pdf_templates.id", ondelete="SET NULL"), nullable=True
|
||||
)
|
||||
|
||||
user: Mapped["User"] = relationship(back_populates="generated_pdfs") # noqa: F821
|
||||
template: Mapped["PdfTemplate | None"] = relationship() # noqa: F821
|
||||
|
||||
16
backend/app/models/pdf_template.py
Normal file
16
backend/app/models/pdf_template.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from sqlalchemy import Boolean, String, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class PdfTemplate(Base):
|
||||
__tablename__ = "pdf_templates"
|
||||
__table_args__ = (UniqueConstraint("name", "locale", name="uq_pdf_templates_name_locale"),)
|
||||
|
||||
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
locale: Mapped[str] = mapped_column(String(10), nullable=False, default="en")
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
html_content: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
is_default: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
||||
Reference in New Issue
Block a user