Files
tsumugu/backend/app/content/documents.py
T
LarsandCursor 2558239bfd
Deploy Development / deploy (push) Successful in 23s
Stelle den ersten nutzbaren Ablauf zum Organisieren und Nachverfolgen bereit.
Anmeldung, Datenraeume, Akten, Vorgaenge, gemeinsame Notizen, Dateien, manuelle Paperless-Referenzen, Aufgaben und unabhaengige Fristen laufen damit in der Entwicklungsumgebung.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-16 22:09:08 +02:00

26 lines
1.0 KiB
Python

"""Bounded note documents. Only paragraph text is stored."""
from __future__ import annotations
from app.core.errors import unprocessable
def clean_document(document: dict) -> dict:
blocks = document.get("blocks")
if not isinstance(blocks, list) or len(blocks) > 400:
raise unprocessable("Die Notiz hat kein gültiges Dokument.")
clean = []
for block in blocks:
if not isinstance(block, dict) or set(block) - {"type", "text"}:
raise unprocessable("Die Notiz enthält einen nicht unterstützten Block.")
if block.get("type") != "paragraph" or not isinstance(block.get("text"), str):
raise unprocessable("Die Notiz enthält einen nicht unterstützten Block.")
if len(block["text"]) > 20000:
raise unprocessable("Ein Absatz ist zu lang.")
clean.append({"type": "paragraph", "text": block["text"]})
return {"version": 1, "blocks": clean}
def document_text(document: dict) -> str:
return "\n".join(block["text"] for block in document.get("blocks", []))