Development
This commit is contained in:
parent
113328c566
commit
01a636e842
16 changed files with 388 additions and 502 deletions
|
|
@ -92,40 +92,41 @@ def passes(req, level):
|
|||
|
||||
# Snapshot helpers ====================================================
|
||||
|
||||
def snap_text(val):
|
||||
"""Return the plain-text representation of a snapshot before/after value."""
|
||||
if val is None:
|
||||
def build_snap_val(changes):
|
||||
"""Return a brief summary of changed field names for the history table cell."""
|
||||
if not changes:
|
||||
return ''
|
||||
if isinstance(val, dict) and len(val) == 1:
|
||||
k, v = next(iter(val.items()))
|
||||
return f'{k}: {v}'
|
||||
if isinstance(val, (dict, list)):
|
||||
return json.dumps(val, separators=(',', ':'))
|
||||
return str(val)
|
||||
fields = [c['field'] for c in changes]
|
||||
if len(fields) <= 2:
|
||||
return e(', '.join(fields))
|
||||
return e(f'{fields[0]}, {fields[1]} (+{len(fields) - 2} more)')
|
||||
|
||||
|
||||
def build_snap_val(val):
|
||||
"""Return truncated escaped HTML for a snapshot before/after table cell."""
|
||||
text = snap_text(val)
|
||||
if not text:
|
||||
def snap_expand_row(changes, colspan):
|
||||
"""Return a hidden <tr> with a per-field change table."""
|
||||
if not changes:
|
||||
return ''
|
||||
trunc = (text[:23] + '…') if len(text) > 24 else text
|
||||
return e(trunc)
|
||||
|
||||
|
||||
def snap_expand_row(before_val, after_val, colspan):
|
||||
"""Return a hidden <tr> that expands with full before/after content."""
|
||||
def box(label, val):
|
||||
text = snap_text(val) if val is not None else ''
|
||||
if isinstance(val, (dict, list)):
|
||||
text = json.dumps(val, indent=2)
|
||||
body = e(text) if text else '<em class="snap-expand-none">(none)</em>'
|
||||
return (
|
||||
'<div class="snap-expand-col">'
|
||||
f'<span class="snap-expand-label">{label}</span>'
|
||||
f'<pre class="snap-expand-pre">{body}</pre></div>'
|
||||
rows = ''
|
||||
for c in changes:
|
||||
bval = c['before'] if c['before'] is not None else ''
|
||||
aval = c['after'] if c['after'] is not None else ''
|
||||
rows += (
|
||||
'<tr>'
|
||||
f'<td class="snap-expand-field">{e(c["field"])}</td>'
|
||||
f'<td class="snap-expand-val">{e(bval) if bval else "<em>(none)</em>"}</td>'
|
||||
f'<td class="snap-expand-val">{e(aval) if aval else "<em>(none)</em>"}</td>'
|
||||
'</tr>'
|
||||
)
|
||||
inner = f'<div class="snap-expand-cols">{box("Before", before_val)}{box("After", after_val)}</div>'
|
||||
inner = (
|
||||
'<table class="snap-expand-table">'
|
||||
'<thead><tr>'
|
||||
'<th class="snap-expand-th">Field</th>'
|
||||
'<th class="snap-expand-th">Before</th>'
|
||||
'<th class="snap-expand-th">After</th>'
|
||||
'</tr></thead>'
|
||||
f'<tbody>{rows}</tbody>'
|
||||
'</table>'
|
||||
)
|
||||
return f'<tr hidden><td colspan="{colspan}" class="snap-expand-cell">{inner}</td></tr>'
|
||||
|
||||
# Form helpers ========================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue