mirror of
https://git.hiabuto.net/C3MA/CCMA.git
synced 2026-09-06 03:20:49 +02:00
Insert a working repeat block instead of its description
The placeholder chooser showed repeat blocks as "{{#claims}} … {{/claims}}" and
inserted exactly that on double-click -- the ellipsis is a label, so the saved
template rendered a literal "…" per claim instead of the claim.
Chooser rows are data now: each carries the text it reads as and, separately,
the snippet it inserts. A block contributes a complete, ready-to-edit block with
a sample line built from its own placeholders, and lands on a line of its own
when the cursor sits behind existing text.
Covered from both sides: the snippets are checked against the template validator
and renderer, and a UI test drives the real dialog -- insert, save, send -- and
asserts the mail carries actual claim lines. The Tk tests share one root (the
icon library binds its images to the first one) and skip without a display.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
592c5482d6
commit
d3dbb5e96d
@@ -11,6 +11,7 @@ from ccma.domain.mail_templates import (
|
||||
MAIL_TEMPLATES,
|
||||
MailTemplateError,
|
||||
default_mail_template,
|
||||
placeholder_entries,
|
||||
template_spec,
|
||||
)
|
||||
from ccma.domain.models import HOUSEKEEPER_MEMBER_FIELD_LABELS
|
||||
@@ -81,6 +82,7 @@ class OptionsDialog(tk.Toplevel):
|
||||
self.mail_template_var = tk.StringVar(value=MAIL_TEMPLATES[0].label)
|
||||
self.mail_template_subject_var = tk.StringVar()
|
||||
self.mail_template_hint_var = tk.StringVar()
|
||||
self.mail_template_snippets: dict[str, str] = {}
|
||||
self.title("Optionen")
|
||||
self.transient(master.winfo_toplevel())
|
||||
self.grab_set()
|
||||
@@ -1031,18 +1033,15 @@ class OptionsDialog(tk.Toplevel):
|
||||
self.mail_template_body.delete("1.0", "end")
|
||||
self.mail_template_body.insert("1.0", body)
|
||||
self.mail_template_placeholders.delete(*self.mail_template_placeholders.get_children())
|
||||
for name, description in spec.placeholders:
|
||||
self.mail_template_placeholders.insert(
|
||||
"", "end", values=(f"{{{{{name}}}}}", description)
|
||||
# The row text is a readable label; what actually gets inserted is the entry's
|
||||
# snippet, which for a repeat block is the whole block and not its description.
|
||||
self.mail_template_snippets = {}
|
||||
for entry in placeholder_entries(key):
|
||||
label = f" {entry.label}" if entry.indented else entry.label
|
||||
row = self.mail_template_placeholders.insert(
|
||||
"", "end", values=(label, entry.description)
|
||||
)
|
||||
for name, description, items in spec.blocks:
|
||||
self.mail_template_placeholders.insert(
|
||||
"", "end", values=(f"{{{{#{name}}}}} … {{{{/{name}}}}}", description)
|
||||
)
|
||||
for item_name, item_description in items:
|
||||
self.mail_template_placeholders.insert(
|
||||
"", "end", values=(f" {{{{{item_name}}}}}", item_description)
|
||||
)
|
||||
self.mail_template_snippets[row] = entry.snippet
|
||||
|
||||
def _capture_mail_template(self) -> None:
|
||||
if not hasattr(self, "mail_template_body"):
|
||||
@@ -1081,10 +1080,19 @@ class OptionsDialog(tk.Toplevel):
|
||||
selected = self.mail_template_placeholders.selection()
|
||||
if not selected:
|
||||
return
|
||||
value = str(self.mail_template_placeholders.item(selected[0], "values")[0]).strip()
|
||||
self.mail_template_body.insert("insert", value)
|
||||
snippet = self.mail_template_snippets.get(selected[0])
|
||||
if not snippet:
|
||||
return
|
||||
# A multi-line block only works on lines of its own, so it starts on a fresh
|
||||
# one instead of being appended to whatever the cursor sat behind.
|
||||
if "\n" in snippet.strip() and not self._mail_cursor_at_line_start():
|
||||
snippet = "\n" + snippet
|
||||
self.mail_template_body.insert("insert", snippet)
|
||||
self.mail_template_body.focus_set()
|
||||
|
||||
def _mail_cursor_at_line_start(self) -> bool:
|
||||
return str(self.mail_template_body.index("insert")).split(".")[1] == "0"
|
||||
|
||||
def _save_mail_templates(self) -> None:
|
||||
self._capture_mail_template()
|
||||
for key, (subject, body) in self.mail_template_edits.items():
|
||||
|
||||
Reference in New Issue
Block a user