{% extends "adminsite/base.html" %} {% import "adminsite/_icons.html" as icons %} {% import "adminsite/_values.html" as values %} {% block page_title %}{{ heading }} ยท {{ title }}{% endblock %} {% block breadcrumb %} {% endblock %} {% block header_class %}lg:pt-2 lg:pb-5{% endblock %} {#- The first choice on the page, such as a status, stands beside the name. -#} {% set first = namespace(path=none, value="") %} {% for path, label, value, url in rows if first.path is none and value and view._fields.field_for(path).widget == "select" and not view._fields.hides(record, path) %} {% set first.path = path %}{% set first.value = value %} {% endfor %} {#- Who last changed the record, from the history the page already holds. -#} {% set changed = (history or [])|selectattr("entry.succeeded")|first %} {% block header %}

{{ heading }}

{% if first.path %} {{ values.badge(view._fields.field_for(first.path), view._fields.value_at(record, first.path), first.value) }} {% endif %}
{% if changed %}

{{ _('Last changed by {who} on {when}', who=changed.who, when=changed.when) }}

{% endif %}
{% endblock %} {% block header_actions %} {#- Each action a button of the header's own row, which wraps where they do not all fit. On a phone they fold into the menu below. -#} {% if can_edit %} {{ icons.icon("pencil") }}{{ _('Edit') }} {% endif %} {#- The menu holds delete, and on a phone the record's actions as well. -#} {% if can_delete or record_actions %} {% endif %} {% endblock %} {% block content %} {% include "adminsite/_action_forms.html" %} {#- The status beside the name leaves the rows, unless it is all they hold. -#} {% set skipped = first.path if first.path and rows|length > 1 else none %} {% set by_path = {} %} {% for row in rows %}{% set ignored = by_path.update({row[0]: row}) %}{% endfor %} {#- A table for each panel of the view's layout, and each tab, with its fields in the order placed; the fields outside them make a table of their own, the first named after the model. -#} {% set sections = [] %} {% for card in layout %} {% if card.kind == "tabs" %} {% for tab in card.children %} {% set ignored = sections.append((tab.title, "", tab.paths())) %} {% endfor %} {% else %} {% set ignored = sections.append((card.title or (view.label if loop.first else ""), card.description, card.paths())) %} {% endif %} {% endfor %}
{% if history is not none %}
{% else %}
{% endif %}
{% for title, description, paths in sections %} {% set listed = paths|reject("equalto", skipped)|list %} {% if listed %} {#- A row per field, its label in a column of its own, so the labels read down one line and the values line up beside them. -#}
{% if title %}

{{ title }}

{% if description %}

{{ description }}

{% endif %}
{% endif %}
{% for path in listed %} {% set path, label, value, url = by_path[path] %} {% set item = view._fields.field_for(path) %} {#- A JSON document with a schema it fits reads as labelled values. -#} {% set stored = view._fields.value_at(record, path) if item.widget == "json" and not view._fields.hides(record, path) else none %} {% set reading = item.form_document(record, stored) if stored is not none and item.form_document is defined else none %}
{{ label }}
{% if reading is not none %}
{%- with switch_views = [("values", _("Values")), ("json", "JSON")], switch_label = label -%} {% include "adminsite/_document_switch.html" %} {%- endwith -%}
{% endif %} {% if view._fields.hides(record, path) %} {#- Read through a record its own view keeps from this user. -#} {{ value }} {% elif item.widget in ("file", "image") and value %} {% set address = urls.file(view, path, view._fields.value_at(record, path)) %} {% if item.widget == "image" %} {{ value }} {% else %} {{ value }} {% endif %} {% elif url and value %} {{ value }} {% elif path in many and many[path].names %} {#- Each record a link to many holds opens its own page. -#} {%- for name, opens in many[path].names -%} {%- if opens -%} {{ name }} {%- else -%} {{ name }} {%- endif -%} {%- if not loop.last %}, {% endif -%} {%- endfor -%} {%- if many[path].more > 0 %}{{ _(" and {count} more", count="{:,}".format(many[path].more)) }}{% endif -%} {% elif item.widget in ("select", "checkbox") and value %} {{ values.badge_or_text(item, view._fields.value_at(record, path), value) }} {% elif item.widget == "number" and value %} {{ value }} {% elif item.widget == "json" and stored is not none %} {% with outline = item.outline(stored), pretty = item.laid_out(stored) %} {% if reading is not none %} {% with shown = reading.shown(stored) %}{% include "adminsite/_document_view.html" %}{% endwith %} {% else %} {% include "adminsite/_json.html" %} {% endif %} {% endwith %} {% elif item.widget == "textarea" and value %}
{{ value }}
{% elif value %} {{ value }} {% else %} {% include "adminsite/_empty.html" %} {% endif %}
{% endfor %}
{% endif %} {% endfor %} {% for table in children %}

{{ table.label }}

{{ table.rows|length }}
{% for header in table.headers %} {% endfor %} {% for cells in table.rows %} {% for text in cells %} {% endfor %} {% else %} {% endfor %}
{{ header }}
{% if text %}{{ text }}{% else %}{% include "adminsite/_empty.html" %}{% endif %}
{{ _('None yet.') }}
{% endfor %}
{% if history is not none %}
{% set items = history %} {% set show_record = False %} {% include "adminsite/_history.html" %} {% if older_history %} {{ _('Older entries are on the Activity page') }} {% endif %}
{% endif %}
{% if can_delete %} {% endif %} {% endblock %}