{% macro render_field(construct, field, type, view, data=None, ds=None, errors=None) %} {% if type.secret and data %}
{{ icon("lock", style="font-size: 14px;") }} ••••••••
{{ icon("lock", style="font-size: 14px;") }} ••••••••
{{ _render_field_internal(construct, field, type, view, data=None, ds=ds, skip_label=True) }}
{% else %} {{ _render_field_internal(construct, field, type, view, data, ds, errors=errors) }} {% endif %} {% endmacro %} {% macro _render_field_internal(construct, field, type, view, data=None, ds=None, skip_label=False, disabled=False, errors=None) %} {% if type.field_type == 'bool' %}
{% elif type.field_type == 'set' %}
{% if not skip_label %}{% endif %} {% set values = data[field] if data and data[field] else [] %}
{% for key, label_key in type.sets.items() %}
{% endfor %}
{% elif type.readonly == True and type.field_type != 'list' %}
{% if not skip_label %}{% endif %} {% set value = type.format_value(field,data) if data else "" %} {% if type.orgmode %}
{{ value | orgmode }}
{% elif type.form_input_type() == 'richtext' %}
{{ value | markdown }}
{% else %}

{{ value }}

{% endif %}
{% elif type.field_type == 'related' %}
{% if not skip_label %}{% endif %}
{% set value = type.form_value(data) if data else None %}

{% elif type.field_type == 'manyrelated' %}
{% if not skip_label %}{% endif %} {% set current_items = type.form_value(data) if data else [] %} {% set staged_field = ((data.many_related_new if data else none) or {}).get(field) or {} %}
{% set search_result = type.related_class().search() %}
{% if not disabled and type.create == 'quick' %} {# noscript so these inputs never submit alongside the JS chips #} {% elif not disabled and type.create == 'form' %} {% endif %}
{% for item in current_items %} {% endfor %}
{% for item in current_items %} {{ type.render_display(item) }} {% endfor %} {% for staged_value in staged_field.get('quick') or [] %} {{ staged_value }} {{ construct.t('crud-pending-new') }} {% endfor %} {% if not disabled %} {% endif %}
{% if not disabled and type.create == 'form' %}
{% for item in staged_field.get('new') or [] %} {{ render_newrel_panel(construct, field, type, loop.index0, item, errors) }} {% endfor %}
{% endif %}
{% elif type.field_type == 'enum' %}
{% if not skip_label %}{% endif %}
{% elif type.field_type == 'list' %}
{% if not skip_label %}{% endif %} {% if data and ds %} {% set items = ds.get_list(data, field) %} {% if items %} {% if type.layout == 'table' %}
{% if type.columns %} {% for col in type.columns %} {% set t = type.list_class()._schema[col] %} {% endfor %} {% else %} {% for f, t in type.list_class()._schema.items() if t.field_type != 'pk' and t.visible_form %} {% endfor %} {% endif %} {% if not type.readonly %} {% endif %} {% for item in items %} {% set list_ds = type.list_class() %} {% set list_pk_field = list_ds._primary_key %} {% set item_id = item[list_pk_field] %} {% set columns_to_render = type.columns if type.columns else list_ds._schema.keys() %} {% for f in columns_to_render if list_ds._schema[f].field_type != 'pk' and (type.columns or list_ds._schema[f].visible_form) %} {% set t = list_ds._schema[f] %} {% endfor %} {% if not type.readonly %} {% endif %} {% endfor %}
{{ construct.t(t.name).capitalize() }}{{ construct.t(t.name).capitalize() }} {% if type.can_delete %}{{ icon("delete", style="font-size: 16px;") }}{% endif %}
{% if type.readonly or t.readonly %} {% if t.field_type == 'bool' %} {% if item[f] %} {{ icon("check", style="color: var(--fcu-success); font-variation-settings: 'FILL' 1") }} {% else %} {{ icon("cancel", style="color: var(--fcu-danger); font-variation-settings: 'FILL' 1") }} {% endif %} {% elif t.field_type == 'set' %} {% if item[f] %}
{% for v in item[f] %} {% if v in t.sets %}{{ construct.t(t.sets[v]) }}{% endif %} {% endfor %}
{% endif %} {% elif t.field_type == 'related' %} {% set curr = item %} {% for part in t.related_field.split('.') %} {% set curr = curr[part] %} {% endfor %} {{ curr }} {% elif t.field_type == 'enum' %} {{ t.format_value(f, item) }} {% elif t.orgmode %}
{{ t.format_value(f, item) | orgmode }}
{% elif t.form_input_type() == 'richtext' %}
{{ t.format_value(f, item) | markdown }}
{% else %} {{ t.format_value(f, item) }} {% endif %} {% else %} {% set input_name = field ~ "-" ~ item_id ~ "-" ~ f %} {% if t.field_type == 'bool' %} {% elif t.field_type == 'set' %} {% set values = item[f] if item and item[f] else [] %}
{% for key, label_key in t.sets.items() %}
{% endfor %}
{% elif t.field_type == 'related' %} {% elif t.field_type == 'enum' %} {% elif t.form_input_type() == 'richtext' %} {% set editor_id = 'editor_' ~ input_name %} {% set value = item[f] if item[f] is not none else '' %}
{% else %} {% set list_err = t.validate_value(item[f], item) if item else None %} {% if list_err %} {{ construct.t(list_err.key, list_err.args) }} {% endif %} {% endif %} {% endif %}
{% if type.can_delete %} {% endif %}
{% elif type.layout == 'form' %}
{% for item in items %} {% set list_ds = type.list_class() %} {% set list_pk_field = list_ds._primary_key %} {% set item_id = item[list_pk_field] %}

{{ item }}

{% if not type.readonly %}
{% if type.can_delete %} {% endif %}
{% endif %}
{% if type.template %} {% include type.template %} {% else %}
{% set columns_to_render = type.columns if type.columns else list_ds._schema.keys() %} {% for f in columns_to_render if list_ds._schema[f].field_type != 'pk' and (type.columns or list_ds._schema[f].visible_form) %} {% set t = list_ds._schema[f] %}
{% if type.readonly or t.readonly %} {% if t.field_type == 'bool' %}
{% if item[f] %} {{ icon("check", style="color: var(--fcu-success); font-variation-settings: 'FILL' 1") }} {% else %} {{ icon("cancel", style="color: var(--fcu-danger); font-variation-settings: 'FILL' 1") }} {% endif %}
{% elif t.field_type == 'set' %} {% if item[f] %}
{% for v in item[f] %} {% if v in t.sets %}{{ construct.t(t.sets[v]) }}{% endif %} {% endfor %}
{% endif %} {% elif t.field_type == 'related' %} {% set curr = item %} {% for part in t.related_field.split('.') %} {% set curr = curr[part] %} {% endfor %}

{{ curr }}

{% elif t.field_type == 'enum' %}

{{ t.format_value(f, item) }}

{% elif t.orgmode %}
{{ t.format_value(f, item) | orgmode }}
{% elif t.form_input_type() == 'richtext' %}
{{ t.format_value(f, item) | markdown }}
{% else %}

{{ t.format_value(f, item) }}

{% endif %} {% else %} {% set input_name = field ~ "-" ~ item_id ~ "-" ~ f %} {% if t.field_type == 'bool' %}
{% elif t.field_type == 'set' %} {% set values = item[f] if item and item[f] else [] %}
{% for key, label_key in t.sets.items() %}
{% endfor %}
{% elif t.field_type == 'related' %} {% elif t.field_type == 'enum' %} {% elif t.form_input_type() == 'richtext' %} {% set editor_id = 'editor_' ~ input_name %} {% set value = item[f] if item[f] is not none else '' %}
{% else %} {% set list_err = t.validate_value(item[f], item) if item else None %} {% if list_err %} {{ construct.t(list_err.key, list_err.args) }} {% endif %} {% endif %} {% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %} {% else %}

{{ construct.t("crud-no-items-found") }}

{% endif %} {% endif %} {% if not type.readonly and type.can_add %}
{% endif %}
{% elif type.form_input_type() == 'textarea' %}
{% if not skip_label %}{% endif %} {% set value = type.format_value(field, data) if data else '' %} {% set column = ds.model[field] if ds else None %} {% set maxlength = column.type.length if column and column.type and column.type.length else '' %} {% set error = errors.get(field) if errors else (type.validate_value(value) if type.validate_value and data else None) %} {% if error %} {{ construct.t(error.key, error.args) }} {% endif %}
{% elif type.form_input_type() == 'richtext' %} {% set editor_id = 'editor_' ~ field %} {% set value = type.format_value(field, data) if data else '' %} {% set column = ds.model[field] if ds else None %} {% set maxlength = column.type.length if column and column.type and column.type.length else '' %}
{% if not skip_label %}{% endif %}
{% set error = errors.get(field) if errors else (type.validate_value(value) if type.validate_value and data else None) %} {% if error %} {{ construct.t(error.key, error.args) }} {% endif %}
{% else %}
{% if not skip_label %}{% endif %} {% set value = type.format_value(field,data) if data else None %} {% set maxlength = type.length if type.length else '' %} {% set error = errors.get(field) if errors else (type.validate_value(value) if type.validate_value and data else None) %} {% if error %} {{ construct.t(error.key, error.args) }} {% endif %}
{% endif %} {% endmacro %} {% macro render_newrel_subfield(construct, input_name, t, value=None, error=None) %} {# One inline-create panel input for a ManyRelated create="form" field. Supports the types in ManyRelated.INLINE_FORM_TYPES; text renders as a plain textarea (no ProseMirror inside cloned