{% extends "base_template.html" %} {# action is a logic value ("Create"/"Edit") coming from the route; translate it only where it is shown. #} {% set action_label = _('Edit') if action == 'Edit' else _('Create') %} {% block title %}{{ action_label }} {{ model_name }} - {{ _('Admin') }}{% endblock %} {% block breadcrumb %} {% endblock %} {% block content %}

{{ action_label }} {{ model_name }}

{% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} {% for category, message in messages %} {% endfor %} {% endif %} {% endwith %}
{# A bare test app has no CSRFProtect, so the global may not exist; every real product initialises it and emits the token. #} {% if csrf_token is defined %}{% endif %}
{% for col in columns %}
{% set col_type = col.type.upper().split('(')[0] %} {# What the field shows. A form posted back after a refusal shows what was typed (values, as strings); otherwise the stored value, or nothing on a fresh form. #} {% if values %} {% set current = values.get(col.name) %} {% elif record %} {% set current = record.__dict__.get(col.name) %} {% else %} {% set current = none %} {% endif %} {% if col_type in ('TEXT', 'LONGTEXT', 'MEDIUMTEXT') %} {% elif col_type == 'BOOLEAN' or col_type == 'TINYINT' %}
{% else %} {% if col_type in ('INTEGER', 'INT', 'BIGINT', 'SMALLINT', 'FLOAT', 'DECIMAL', 'NUMERIC', 'DOUBLE') %} {% set input_type = 'number' %} {% elif col_type == 'DATETIME' or col_type == 'TIMESTAMP' %} {% set input_type = 'datetime-local' %} {% elif col_type == 'DATE' %} {% set input_type = 'date' %} {% elif col.secret %} {% set input_type = 'password' %} {% else %} {% set input_type = 'text' %} {% endif %} {% if current is not none and current is not string and input_type == 'datetime-local' %} {% set current = current.strftime('%Y-%m-%dT%H:%M') %} {% elif current is not none and current is not string and input_type == 'date' %} {% set current = current.strftime('%Y-%m-%d') %} {% endif %} {% endif %}
{% endfor %}
{{ _('Cancel') }}
{% endblock %}