Strukturiere index.html und inhalt.md nach Vorgangshierarchie.
Deploy Development / deploy (push) Successful in 28s
Test Suite / pytest-backend (push) Failing after 2m0s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 9s

Kapitel, Teilvorgänge und Schriftstücke erscheinen verschachtelt; Anlagen, Belege, Versand und Anmerkungen sind dem jeweiligen Eintrag zugeordnet, mit Inhaltsverzeichnis und klarerer HTML-Darstellung.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-18 14:56:36 +02:00
1 parent 97401a6d84
commit 59434a4045
2 files changed
+302 -46

No files matched your search

+297 -46
View File
@@ -136,6 +136,15 @@ class Entry:
}
@dataclass
class OverviewNode:
kind: str
title: str
label: str | None = None
entry: Entry | None = None
children: list[OverviewNode] = field(default_factory=list)
@dataclass
class ExportPlan:
matter_title: str
@@ -263,7 +272,7 @@ def _plan(conn, actor, matter_id, context, selected, assignments, media_root) ->
)
_attach_replies(conn, actor, page, entries, leaves)
_stitch_replies(files, entries)
files = _with_overview(matter["title"], generated, entries, files)
files = _with_overview(matter["title"], generated, root, entries, files)
return ExportPlan(matter["title"], generated, True, [], notices, entries, files, root)
@@ -866,67 +875,309 @@ def _attach_replies(conn, actor, page, entries: list[Entry], leaves: list[Export
entry.replies.append((target["title"], path))
def _with_overview(title: str, generated: str, entries: list[Entry], files: list[tuple[str, bytes]]):
html_doc = _html_overview(title, generated, entries)
markdown = _markdown_overview(title, generated, entries)
def _with_overview(title: str, generated: str, root: ExportNode, entries: list[Entry], files: list[tuple[str, bytes]]):
by_id = {entry.node_id: entry for entry in entries}
sections = _overview_sections(root, by_id)
html_doc = _html_overview(title, generated, sections)
markdown = _markdown_overview(title, generated, sections)
return [("index.html", html_doc.encode("utf-8")), ("inhalt.md", markdown.encode("utf-8")), *files]
def _html_overview(title: str, generated: str, entries: list[Entry]) -> str:
items = []
for entry in entries:
bits = [f"<h2>{html.escape(entry.title)}</h2>", f"<p>{html.escape(entry.kind_label)}</p>"]
facts = _fact_lines(entry, generated)
if facts:
bits.append("<ul>" + "".join(f"<li>{html.escape(line)}</li>" for line in facts) + "</ul>")
if entry.summary:
bits.append(f"<p>Kurzfassung: {html.escape(entry.summary)}</p>")
for label, path in _entry_links(entry):
bits.append(f'<p><a href="{_href(path)}">{html.escape(label)}</a></p>')
for reply_title, path in entry.replies:
bits.append(
f'<p>Antwort auf <a href="{_href(path)}">{html.escape(reply_title)}</a></p>'
)
if entry.notice:
bits.append(f"<p>{html.escape(entry.notice)}</p>")
items.append(f"<article>{''.join(bits)}</article>")
body = "".join(items) or "<p>Die bestätigte Auswahl enthält keinen ausgebbaren Inhalt.</p>"
def _overview_sections(root: ExportNode, entries: dict[str, Entry]) -> list[OverviewNode]:
found: list[OverviewNode] = []
for child in root.children:
section = _overview_node(child, entries)
if section is not None:
found.append(section)
return found
def _overview_node(node: ExportNode, entries: dict[str, Entry]) -> OverviewNode | None:
if node.kind in {"matter", "chapter"}:
children = []
for child in node.children:
section = _overview_node(child, entries)
if section is not None:
children.append(section)
if not children:
return None
return OverviewNode("container", node.title, node.label or _KIND_LABEL.get(node.kind, ""), None, children)
if node.kind == "binding":
return _overview_binding(node, entries)
return None
def _overview_binding(node: ExportNode, entries: dict[str, Entry]) -> OverviewNode | None:
groups: list[OverviewNode] = []
annotations = [
OverviewNode("leaf", child.title, _label(child), entries[child.id])
for child in node.children
if child.kind == "annotation" and child.id in entries
]
if annotations:
groups.append(OverviewNode("group", "Anmerkungen", None, None, annotations))
anlagen = [
OverviewNode("leaf", child.title, _label(child), entries[child.id])
for child in node.children
if child.kind == "attachment" and child.id in entries
]
if anlagen:
groups.append(OverviewNode("group", "Anlagen", None, None, anlagen))
belege: list[OverviewNode] = []
versand: list[OverviewNode] = []
for dispatch in node.children:
if dispatch.kind != "dispatch":
continue
items = [
OverviewNode("leaf", item.title, _label(item), entries[item.id])
for item in dispatch.children
if item.kind in {"dispatch_item", "evidence"} and item.id in entries
]
if not items:
continue
bucket = "Belege" if (dispatch.label or "").startswith("Beleg") else (dispatch.label or "Versand")
target = belege if bucket == "Belege" else versand
target.append(OverviewNode("group", dispatch.title, bucket, None, items))
if belege:
groups.append(OverviewNode("group", "Belege", None, None, belege))
if versand:
groups.extend(versand)
host = entries.get(node.id)
if host is None and not groups:
return None
return OverviewNode("binding", node.title, node.label or _label(node), host, groups)
def _overview_toc(sections: list[OverviewNode], counter: list[int]) -> tuple[list[tuple[str, str]], list[int]]:
items: list[tuple[str, str]] = []
def walk(nodes: list[OverviewNode]) -> None:
for node in nodes:
if node.kind not in {"container", "binding"}:
continue
counter[0] += 1
anchor = f"inhalt-{counter[0]}"
label = node.title
if node.label and node.kind == "container":
label = f"{node.label}: {node.title}"
items.append((anchor, label))
if node.kind == "container":
walk(node.children)
walk(sections)
return items, counter
def _html_overview(title: str, generated: str, sections: list[OverviewNode]) -> str:
counter = [0]
toc, _counter = _overview_toc(sections, counter)
counter[0] = 0
toc_html = ""
if toc:
toc_html = (
'<nav class="overview-toc" aria-label="Inhalt">'
"<h2>Inhalt</h2><ol>"
+ "".join(f'<li><a href="#{anchor}">{html.escape(label)}</a></li>' for anchor, label in toc)
+ "</ol></nav>"
)
body = _html_overview_nodes(sections, generated, counter) or "<p>Die bestätigte Auswahl enthält keinen ausgebbaren Inhalt.</p>"
return (
"<!DOCTYPE html><html lang=\"de\"><head><meta charset=\"utf-8\">"
f"<title>Übergabe {html.escape(title)}</title>"
"<style>body{font-family:Segoe UI,sans-serif;line-height:1.45;max-width:46rem;margin:2rem auto;padding:0 1rem;color:#1c1b18}"
"a{color:#085041}article{border-top:1px solid #ddd;padding:1rem 0}</style></head><body>"
f"<h1>Übergabe {html.escape(title)}</h1>"
f"<p>Erzeugt am {html.escape(generated)}. Fachliche Daten stehen bei den einzelnen Inhalten und sind kein Erzeugungszeitpunkt.</p>"
f"{body}</body></html>"
"<style>"
":root{color:#1c1b18;background:#faf9f6;--line:#d8d3c8;--accent:#085041;--panel:#f0ebe3}"
"body{font-family:Segoe UI,system-ui,sans-serif;line-height:1.5;max-width:52rem;margin:0 auto;padding:2rem 1.25rem 3rem}"
"a{color:var(--accent)}"
".overview-toc{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:1rem 1.25rem;margin:1.5rem 0 2rem}"
".overview-toc ol{margin:0;padding-left:1.25rem}"
".overview-branch{border:1px solid var(--line);border-radius:12px;padding:0.75rem 1rem 1rem;margin:1rem 0;background:#fff}"
".overview-branch > .branch-head{font-size:1.05rem;font-weight:600;margin:0 0 0.75rem}"
".overview-branch .branch-kind{display:inline-block;font-size:0.75rem;font-weight:600;letter-spacing:0.04em;text-transform:uppercase;color:#5c574e;margin-right:0.5rem}"
".overview-entry{border-top:1px solid var(--line);padding:1rem 0 0.5rem;margin-top:0.75rem}"
".overview-entry:first-of-type{border-top:none;margin-top:0;padding-top:0}"
".entry-head{display:flex;flex-wrap:wrap;gap:0.35rem 0.75rem;align-items:baseline;margin-bottom:0.35rem}"
".entry-title{font-size:1.1rem;font-weight:600;margin:0}"
".entry-kind{font-size:0.8rem;color:#5c574e}"
".entry-links{display:flex;flex-wrap:wrap;gap:0.5rem;margin:0.5rem 0}"
".entry-links a{display:inline-block;padding:0.25rem 0.65rem;border-radius:999px;background:var(--panel);text-decoration:none;font-size:0.9rem}"
".entry-group{margin:0.75rem 0 0 0.5rem;padding-left:0.85rem;border-left:3px solid var(--line)}"
".entry-group-title{font-size:0.95rem;font-weight:600;margin:0 0 0.35rem}"
".entry-group ul{margin:0.25rem 0 0;padding-left:1.1rem}"
".entry-leaf{margin:0.2rem 0}"
".entry-meta{font-size:0.92rem;color:#3d3a34;margin:0.35rem 0}"
".entry-notice{font-size:0.92rem;color:#6b4a12;background:#fff8ea;border-radius:8px;padding:0.5rem 0.65rem;margin-top:0.5rem}"
"</style></head><body>"
f"<header><h1>Übergabe {html.escape(title)}</h1>"
f"<p class=\"entry-meta\">Erzeugt am {html.escape(generated)}. Fachliche Daten stehen bei den einzelnen Inhalten und sind kein Erzeugungszeitpunkt.</p></header>"
f"{toc_html}{body}</body></html>"
)
def _markdown_overview(title: str, generated: str, entries: list[Entry]) -> str:
def _html_overview_nodes(sections: list[OverviewNode], generated: str, counter: list[int]) -> str:
parts = []
for section in sections:
parts.append(_html_overview_node(section, generated, counter, depth=2))
return "".join(parts)
def _html_overview_node(node: OverviewNode, generated: str, counter: list[int], depth: int) -> str:
counter[0] += 1
anchor = f"inhalt-{counter[0]}"
if node.kind == "container":
inner = "".join(_html_overview_node(child, generated, counter, depth + 1) for child in node.children)
label = f'<span class="branch-kind">{html.escape(node.label)}</span>' if node.label else ""
return (
f'<section class="overview-branch" id="{anchor}">'
f'<p class="branch-head">{label}{html.escape(node.title)}</p>{inner}</section>'
)
if node.kind == "binding":
bits = [
f'<section class="overview-entry" id="{anchor}">',
'<div class="entry-head">',
f'<h{min(depth, 6)} class="entry-title">{html.escape(node.title)}</h{min(depth, 6)}>',
]
if node.label:
bits.append(f'<span class="entry-kind">{html.escape(node.label)}</span>')
bits.append("</div>")
if node.entry:
bits.append(_html_entry_body(node.entry, generated))
for child in node.children:
bits.append(_html_overview_group(child, generated))
bits.append("</section>")
return "".join(bits)
return ""
def _html_overview_group(node: OverviewNode, generated: str) -> str:
if node.kind == "leaf":
return _html_leaf(node.entry, generated)
if node.kind != "group":
return ""
subtitle = f" · {html.escape(node.label)}" if node.label and node.title != node.label else ""
title = html.escape(node.title)
if node.children and all(child.kind == "leaf" for child in node.children):
inner = "".join(_html_leaf(child.entry, generated) for child in node.children)
return f'<div class="entry-group"><p class="entry-group-title">{title}{subtitle}</p><ul>{inner}</ul></div>'
inner = "".join(_html_overview_group(child, generated) for child in node.children)
return f'<div class="entry-group"><p class="entry-group-title">{title}{subtitle}</p>{inner}</div>'
def _html_leaf(entry: Entry | None, generated: str) -> str:
if entry is None:
return ""
links = _entry_links(entry)
link_bits = "".join(
f'<a href="{_href(path)}">{html.escape(label)}</a>' for label, path in links
)
meta = f'<span class="entry-kind">{html.escape(entry.kind_label)}</span>' if entry.kind_label else ""
return f'<li class="entry-leaf"><strong>{html.escape(entry.title)}</strong> {meta} — {link_bits}</li>'
def _html_entry_body(entry: Entry, generated: str) -> str:
bits = []
facts = _fact_lines(entry, generated)
if facts:
bits.append("<ul>" + "".join(f"<li>{html.escape(line)}</li>" for line in facts) + "</ul>")
if entry.summary:
bits.append(f'<p class="entry-meta">Kurzfassung: {html.escape(entry.summary)}</p>')
links = _entry_links(entry)
if links:
bits.append(
'<p class="entry-links">'
+ "".join(f'<a href="{_href(path)}">{html.escape(label)}</a>' for label, path in links)
+ "</p>"
)
for reply_title, path in entry.replies:
bits.append(f'<p class="entry-meta">Antwort auf <a href="{_href(path)}">{html.escape(reply_title)}</a></p>')
if entry.notice:
bits.append(f'<p class="entry-notice">{html.escape(entry.notice)}</p>')
return "".join(bits)
def _markdown_overview(title: str, generated: str, sections: list[OverviewNode]) -> str:
lines = [
f"# Übergabe {title}",
"",
f"Erzeugt am {generated}. Fachliche Daten stehen bei den einzelnen Inhalten und sind kein Erzeugungszeitpunkt.",
"",
]
for entry in entries:
lines.append(f"## {entry.title}")
if sections:
lines.extend(["## Inhalt", ""])
for anchor, label in _overview_toc(sections, [0])[0]:
lines.append(f"- [{label}](#{anchor})")
lines.append("")
lines.append(entry.kind_label)
lines.append("")
for fact in _fact_lines(entry, generated):
lines.append(f"- {fact}")
if entry.summary:
lines.append(f"- Kurzfassung: {entry.summary}")
for label, path in _entry_links(entry):
lines.append(f"- [{label}]({_href(path)})")
for reply_title, path in entry.replies:
lines.append(f"- Antwort auf [{reply_title}]({_href(path)})")
if entry.notice:
lines.append("")
lines.append(entry.notice)
lines.append("")
return "\n".join(lines).rstrip() + "\n"
lines.extend(_markdown_overview_nodes(sections, generated, depth=2))
return "\n".join(line for line in lines if line is not None).rstrip() + "\n"
def _markdown_overview_nodes(sections: list[OverviewNode], generated: str, depth: int) -> list[str]:
lines: list[str] = []
counter = [0]
def walk(nodes: list[OverviewNode], level: int) -> None:
for node in nodes:
if node.kind == "container":
counter[0] += 1
anchor = f"inhalt-{counter[0]}"
heading = "#" * min(level, 6)
label = f"{node.label}: " if node.label else ""
lines.extend(["", f"{heading} {label}{node.title}", f"<a id=\"{anchor}\"></a>", ""])
walk(node.children, level + 1)
elif node.kind == "binding":
counter[0] += 1
anchor = f"inhalt-{counter[0]}"
heading = "#" * min(level, 6)
label = f" ({node.label})" if node.label else ""
lines.extend(["", f"{heading} {node.title}{label}", f"<a id=\"{anchor}\"></a>", ""])
if node.entry:
lines.extend(_markdown_entry_body(node.entry, generated))
for child in node.children:
lines.extend(_markdown_group(child, generated, level + 1))
lines.append("")
walk(sections, depth)
return lines
def _markdown_group(node: OverviewNode, generated: str, depth: int) -> list[str]:
if node.kind == "leaf":
return _markdown_leaf(node.entry, depth)
if node.kind != "group":
return []
heading = "#" * min(depth, 6)
title = node.title
if node.label and node.label not in title:
title = f"{title} ({node.label})"
lines = ["", f"{heading} {title}", ""]
for child in node.children:
lines.extend(_markdown_group(child, generated, depth + 1))
return lines
def _markdown_leaf(entry: Entry | None, depth: int) -> list[str]:
if entry is None:
return []
indent = " " * max(0, depth - 4)
links = _entry_links(entry)
if not links:
return [f"{indent}- {entry.title} ({entry.kind_label})"]
link = " · ".join(f"[{label}]({_href(path)})" for label, path in links)
return [f"{indent}- **{entry.title}** ({entry.kind_label}): {link}"]
def _markdown_entry_body(entry: Entry, generated: str) -> list[str]:
lines = []
for fact in _fact_lines(entry, generated):
lines.append(f"- {fact}")
if entry.summary:
lines.append(f"- Kurzfassung: {entry.summary}")
for label, path in _entry_links(entry):
lines.append(f"- [{label}]({_href(path)})")
for reply_title, path in entry.replies:
lines.append(f"- Antwort auf [{reply_title}]({_href(path)})")
if entry.notice:
lines.extend(["", entry.notice])
return lines
def _entry_links(entry: Entry) -> list[tuple[str, str]]:
+5
View File
@@ -976,6 +976,11 @@ def test_correspondence_attachments_stay_under_each_host_in_one_chapter(client,
assert sorted(name.rsplit("/", 1)[-1] for name in second_paths) == ["Anlage B1.pdf", "Anlage B2.pdf"]
assert any("/01 Erstes Schreiben/Belege/" in name.replace("\\", "/") for name in names)
assert not any(name.replace("\\", "/").startswith("01 Schriftwechsel/2026-04") for name in names)
overview_md = _archive(response.content).read("inhalt.md").decode("utf-8")
overview_html = _archive(response.content).read("index.html").decode("utf-8")
assert "#### Anlagen" in overview_md
assert "Anlage A1" in overview_md
assert "entry-group" in overview_html and "Anlagen" in overview_html
def test_export_warns_when_assigned_attachment_is_not_shareable(client, db):