{# A POST button that asks first, with or without JavaScript. {% from "confirm/_form.html" import confirm_form %} {{ confirm_form(url_for("runs.apply", id=run.id), "run-apply", "run-confirm-apply", icon="check", tone="danger") }} With JavaScript on, up-confirm asks in a dialog and core.js adds the confirmation field. With it off, the form posts as it is; the route — which must carry @requires_confirmation (or be a confirm= action) — then answers with the "Are you sure?" page. The macro alone enforces nothing. href where the form posts. label the button label (an l10n key or text). confirm the question (an l10n key or text); none for no question. icon an icon name shown before the label. tone the button colour: danger, warning, primary, secondary, … target Unpoly target (default #main-content). next a return URL, posted as "next". fields extra hidden fields, a dict. class_ replaces the button's classes (default "fcu-btn fcu-btn--"). #} {% macro confirm_form(href, label, confirm=none, icon=none, tone="danger", target=none, next=none, fields=none, class_=none) -%} {%- set _label = t(label) -%} {# nosemgrep: django-no-csrf-token — Flask app; CSRF is handled by {{ csrf_field() }} below, not Django's {% csrf_token %}. #}
{{ csrf_field() }} {%- if next %} {%- endif %} {%- for name, value in (fields or {}).items() %} {%- endfor %}
{%- endmacro %} {% macro _icon(name) %}{{ icon(name, size="sm") }}{% endmacro %}