{#- A JSON document on the record page, read through its schema: each value under its title, lists of objects and maps as small tables, and a part the form writes as JSON as JSON. JSON shows the document itself, laid out and folding. Takes `shown`, from Document.shown, and `outline` and `pretty` for the JSON view. -#} {% import "adminsite/_values.html" as values %} {%- macro value_text(part) -%} {%- if part.kind == "code" -%} {%- if part.empty -%}{{ _('Not set') }} {%- else -%}{{ part.code }}{%- endif -%} {%- elif part.kind == "key" -%} {{ part.text }} {%- elif part.empty -%} {{ _('Not set') }} {%- elif part.field.widget in ("select", "checkbox") and not part.field.multiple|default(false) -%} {{ values.badge(part.field, part.value, part.text) }} {%- elif part.field.widget == "number" -%} {{ part.text }} {%- else -%} {{ part.text }} {%- endif -%} {%- endmacro -%} {%- macro table(part, headers) -%} {%- if part.missing -%} {{ _('Not set') }} {%- elif part.rows -%}
{% for header in headers %} {% endfor %} {% for cells in part.rows %} {% for cell in cells %}{% endfor %} {% endfor %}
{{ header }}
{{ value_text(cell) }}
{%- else -%} {{ _('None') }} {%- endif -%} {%- endmacro -%} {%- macro entries(part) -%}
{% for entry in part.entries %}
{{ entry.label }}
{%- if entry.kind == "group" -%}
{{ entries(entry) }}
{%- elif entry.kind == "rows" -%} {{ table(entry, entry.columns) }} {%- elif entry.kind == "pairs" -%} {{ table(entry, [_("Key"), _("Value")]) }} {%- else -%} {{ value_text(entry) }} {%- endif -%}
{% endfor %}
{%- endmacro -%} {#- Values and JSON switch in the line above, beside the label, from the record page's own markup. -#}
{%- if shown.kind == "group" -%} {{ entries(shown) }} {%- elif shown.kind == "rows" -%} {{ table(shown, shown.columns) }} {%- elif shown.kind == "pairs" -%} {{ table(shown, [_("Key"), _("Value")]) }} {%- else -%} {{ value_text(shown) }} {%- endif -%}
{% include "adminsite/_json.html" %}