b311ab7aa1
Check Cross-Plugin Imports / check (push) Has been cancelled
- Briefpapier (letterheads): Seiten-Setup (A4/A5/Letter, Ränder), Header/Footer-Blöcke, Wasserzeichen, Logo-Upload (DocumentAsset, data:-URI-only) - Druckvorlagen (print_templates): Block-Komposition mit Briefpapier-Ref + entity_type - Block-Registry (document_blocks.py): text/image/shape(line/rect/circle)/table/spacer/divider/placeholder/pagebreak + Modul-Beiträge via document_blocks()-Contract - Renderer (document_renderer.py): Blocks→HTML→PDF via WeasyPrint (SSRF-Sandbox data:-URI-only), @page-Frame mit running header/footer, Placeholder-Beispiel-Defaults gegen StrictUndefined - Contract-Beitrag contacts: document_placeholders/document_data (#359-Muster wie importexport_entities) - 13 neue Endpoints in documents.py: Letterhead-CRUD, Template-CRUD, Assets, document-blocks, document-placeholders, preview (HTML), render (PDF) - Migration: Plugin-SQL 0003 (idempotent) + Alembic 0143 (Dual-Path, RLS fail-closed crm_api) - Frontend: api/documents.ts, Settings→Dokumente (settings_pages), BlockEditor (@dnd-kit Palette/Canvas/Config/Live-Preview-iframe), LetterheadEditor, PrintTemplateEditor, DocumentGenerationDialog (global, ContactDetailPage-Integration) - i18n de/en, api-documentation.md, plugin-development-guide.md, PROGRESS.md Verifikation: 32/32 neue Tests + 9/9 Regressionen, tsc exit 0, Build OK 2.79s, Alembic-Fresh-DB 0143 mit RLS bewiesen, ruff clean
165 lines
4.6 KiB
Python
165 lines
4.6 KiB
Python
"""Pydantic schemas for the Report Generator plugin."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class TemplateCreate(BaseModel):
|
|
name: str = Field(..., min_length=1, max_length=255)
|
|
description: str = Field("", max_length=2000)
|
|
template_type: str = Field("jinja2", pattern="^(jinja2|sql)$")
|
|
content: str = Field(..., min_length=1)
|
|
output_format: str = Field("csv", pattern="^(csv|excel|json|pdf|print)$")
|
|
|
|
|
|
class TemplateUpdate(BaseModel):
|
|
name: str | None = Field(None, min_length=1, max_length=255)
|
|
description: str | None = Field(None, max_length=2000)
|
|
template_type: str | None = Field(None, pattern="^(jinja2|sql)$")
|
|
content: str | None = None
|
|
output_format: str | None = Field(None, pattern="^(csv|excel|json|pdf|print)$")
|
|
|
|
|
|
class TemplateResponse(BaseModel):
|
|
id: str
|
|
name: str
|
|
description: str
|
|
template_type: str
|
|
content: str
|
|
output_format: str
|
|
created_by: str
|
|
deleted_at: datetime | None = None
|
|
created_at: datetime | None = None
|
|
updated_at: datetime | None = None
|
|
|
|
|
|
class ReportGenerateRequest(BaseModel):
|
|
template_id: str = Field(..., min_length=1)
|
|
data: dict = Field(default_factory=dict)
|
|
output_format: str | None = Field(None, pattern="^(csv|excel|json|pdf|print)$")
|
|
|
|
|
|
class PresetReportRequest(BaseModel):
|
|
"""Request to generate a preset report by name."""
|
|
|
|
preset: str = Field(
|
|
...,
|
|
pattern="^(contact_list|calendar_week|calendar_month|company_list|audit_log)$",
|
|
)
|
|
output_format: str = Field("pdf", pattern="^(csv|excel|json|pdf|print)$")
|
|
parameters: dict = Field(default_factory=dict)
|
|
|
|
|
|
class PresetReportInfo(BaseModel):
|
|
"""Metadata for a preset report template."""
|
|
|
|
key: str
|
|
name: str
|
|
description: str
|
|
icon: str
|
|
output_formats: list[str]
|
|
|
|
|
|
class ReportResponse(BaseModel):
|
|
id: str
|
|
template_id: str
|
|
status: str
|
|
output_path: str | None = None
|
|
error_message: str | None = None
|
|
created_by: str
|
|
created_at: datetime | None = None
|
|
updated_at: datetime | None = None
|
|
|
|
|
|
# ─── Documents Generator (Phase L1-L3) ──────────────────────────────────────
|
|
|
|
|
|
class LetterheadCreate(BaseModel):
|
|
name: str = Field(..., min_length=1, max_length=255)
|
|
description: str = Field("", max_length=2000)
|
|
config: dict = Field(default_factory=dict)
|
|
is_default: bool = False
|
|
|
|
|
|
class LetterheadUpdate(BaseModel):
|
|
name: str | None = Field(None, min_length=1, max_length=255)
|
|
description: str | None = Field(None, max_length=2000)
|
|
config: dict | None = None
|
|
is_default: bool | None = None
|
|
|
|
|
|
class LetterheadResponse(BaseModel):
|
|
id: str
|
|
name: str
|
|
description: str
|
|
config: dict
|
|
is_default: bool
|
|
created_by: str
|
|
created_at: datetime | None = None
|
|
updated_at: datetime | None = None
|
|
|
|
|
|
class PrintTemplateCreate(BaseModel):
|
|
name: str = Field(..., min_length=1, max_length=255)
|
|
description: str = Field("", max_length=2000)
|
|
letterhead_id: str | None = None
|
|
entity_type: str = Field("contact", max_length=100)
|
|
blocks: list[dict] = Field(default_factory=list)
|
|
output_format: str = Field("pdf", pattern="^(pdf|print)$")
|
|
|
|
|
|
class PrintTemplateUpdate(BaseModel):
|
|
name: str | None = Field(None, min_length=1, max_length=255)
|
|
description: str | None = Field(None, max_length=2000)
|
|
letterhead_id: str | None = None
|
|
entity_type: str | None = Field(None, max_length=100)
|
|
blocks: list[dict] | None = None
|
|
output_format: str | None = Field(None, pattern="^(pdf|print)$")
|
|
|
|
|
|
class PrintTemplateResponse(BaseModel):
|
|
id: str
|
|
name: str
|
|
description: str
|
|
letterhead_id: str | None = None
|
|
entity_type: str
|
|
blocks: list[dict]
|
|
output_format: str
|
|
created_by: str
|
|
created_at: datetime | None = None
|
|
updated_at: datetime | None = None
|
|
|
|
|
|
class DocumentPreviewRequest(BaseModel):
|
|
"""Preview: render blocks to HTML (live preview in the editor)."""
|
|
|
|
blocks: list[dict]
|
|
letterhead_config: dict | None = None
|
|
entity_type: str | None = None
|
|
data: dict | None = None
|
|
|
|
|
|
class DocumentPreviewResponse(BaseModel):
|
|
html: str
|
|
|
|
|
|
class DocumentRenderRequest(BaseModel):
|
|
"""Render a stored print template with entity data to PDF."""
|
|
|
|
entity_type: str
|
|
entity_id: str
|
|
output_format: str = Field("pdf", pattern="^(pdf|print)$")
|
|
|
|
|
|
class DocumentAssetResponse(BaseModel):
|
|
id: str
|
|
letterhead_id: str | None = None
|
|
filename: str
|
|
mime_type: str
|
|
size_bytes: int
|
|
data_url: str | None = None
|
|
created_at: datetime | None = None
|