{# Rated fields only, grouped by section #}
{% if form_fields %}
{# Build a lookup of image fields by row number for pairing with ratings #}
{% set ns = namespace(pending_section='', has_any=false) %}
{% for field in form_fields %}
{% if field.type == 'section' %}
{% set ns.pending_section = field.label %}
{% elif field.type == 'rating' %}
{% set fid = field.id | string %}
{% set score = form_data.get(fid, '0') | int %}
{% if score > 0 %}
{% set ns.has_any = true %}
{# Flush pending section header #}
{% if ns.pending_section %}
{{ ns.pending_section }}
{% set ns.pending_section = '' %}
{% endif %}
{# Look for an image field on the same grid row #}
{% set photo_url = '' %}
{% for other in form_fields %}
{% if other.type == 'image' and other.row == field.row %}
{% set photo_url = form_data.get(other.id | string, '') %}
{% endif %}
{% endfor %}
{{ field.label }}
{% for i in range(1,6) %}{{ '★' if i <= score else '☆' }}{% endfor %}{{ score }}/5
{% if photo_url %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% if not ns.has_any %}
No rated fields in this inspection.
{% endif %}
{% else %}
No form fields found for this template.
{% endif %}
{# Issues #}
{% if issues %}
Issues ({{ issues|length }})
Severity
Area
Description
Status
{% for issue in issues %}
{{ issue.severity|title }}
{{ issue.area.name }}
{{ issue.description[:80] }}{% if issue.description|length > 80 %}…{% endif %}