Add HTML5 authoring result summaries
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-17 02:15:40 +03:00
parent 04cba89580
commit dde672202c
2 changed files with 22 additions and 0 deletions
@@ -756,6 +756,7 @@ def render_html5_authoring_preview_result(project_id: str, preview: object | Non
<span>{escape(str(routine_name))}</span>
<small>{escape(insert_text[:180] or "insert text unavailable")}</small>
</article>
{_authoring_result_summary("allowed" if allowed else "blocked", diff, checks)}
<div class="check-list">{check_rows}</div>
<div class="diff-list">{diff_rows}</div>
</div>
@@ -801,6 +802,7 @@ def render_html5_authoring_diff_result(
<span>+{escape(str(added))} / -{escape(str(removed))}</span>
<small>{escape(next_version_id or "version preview unavailable")}</small>
</article>
{_authoring_result_summary("changed" if changed else "unchanged", diff, checks)}
<div class="check-list">{check_rows}</div>
<div class="diff-list">{diff_rows}</div>
{apply_form}
@@ -1719,6 +1721,22 @@ def _authoring_changes_summary(changes: Iterable[object]) -> str:
"""
def _authoring_result_summary(state: str, diff: Iterable[object], checks: Iterable[object]) -> str:
diff_list = list(diff)
check_list = list(checks)
diff_kinds = Counter(str(getattr(line, "kind", "") or "CHANGE") for line in diff_list)
check_statuses = Counter(str(getattr(check, "status", "") or "UNKNOWN") for check in check_list)
added = sum(1 for line in diff_list if str(getattr(line, "kind", "")) == "ADD")
removed = sum(1 for line in diff_list if str(getattr(line, "kind", "")) == "REMOVE")
diff_text = ", ".join(f"{name}: {count}" for name, count in sorted(diff_kinds.items())) or "empty diff"
check_text = ", ".join(f"{name}: {count}" for name, count in sorted(check_statuses.items())) or "no checks"
return f"""
<p class="authoring-summary" data-html5-authoring-result-summary>
{escape(state)} · {escape(str(len(diff_list)))} diff lines · +{escape(str(added))} / -{escape(str(removed))} · {escape(diff_text)} · {escape(check_text)}
</p>
"""
def _authoring_detail_summary(diff: Iterable[object], checks: Iterable[object], apply_available: bool) -> str:
diff_list = list(diff)
check_list = list(checks)