{#- Export dialog for table, query and row pages. Expects renderers, display_rows, url_csv_path, url_csv_hidden_args and url_tsv_path, plus: - export_meta: shown in the header and used for download filenames - export_scope and export_scope_description: which rows are exported, e.g. "Filtered rows" and 'where state = "CA"' - export_rows: dict with page (rows on this page), more (true if there are rows beyond this page), later (true past the first page, when the exports start from this page's ?_next= cursor), max (max_returned_rows), total (exact row count or none) and count_url (to fetch the count when total is none). None to show no row counts. - export_single_row: true on row pages, which offer TSV, CSV and JSON for that one row. Otherwise the dialog also offers more JSON shapes, using append_querystring. Formats from plugins use renderer_options for their label, description and which actions to offer. -#} {% set export_base = export_meta or "data" %} {% set export_later = export_rows.later if export_rows else false %} {#- "Include all rows" streams every row from the first one, so offer it on every later page, and on the first page when CSV would stop short -#} {% set csv_stream = export_rows and display_rows and (export_later or (next_url and not (export_rows.total is not none and export_rows.total <= export_rows.max))) and settings.allow_csv_stream %} {% macro rows_text(n) %}{{ "{:,}".format(n) }} row{{ "" if n == 1 else "s" }}{% endmacro %} {#- How many rows an export returns. JSON and plugin formats return the rows on this page; TSV and CSV ask for _size=max, starting from this page. Mirrored by rowsLabel() in export-dialog.js. -#} {% macro rows_label(kind, rows, id) %} {%- set n = rows.page -%} {%- set total = rows.total -%} {%- set up_to = false -%} {%- if kind == "csv" and rows.more -%} {%- if rows.later or (total is none and rows.page < rows.max) -%}{%- set up_to = true -%} {%- elif total is not none -%}{%- set n = [total, rows.max]|min -%} {%- else -%}{%- set n = rows.max -%}{%- endif -%} {%- endif -%} {%- set complete = not up_to and not rows.later and (not rows.more or (total is not none and n >= total)) -%} {%- if up_to -%}Up to {{ rows_text(rows.max) }}{% if rows.later %} from this page{% endif %} {%- elif n == 0 -%}No rows {%- elif rows.later -%}{{ rows_text(n) }} on this page {%- elif complete -%}All {{ rows_text(total if total is not none else n) }} {%- elif total is not none -%}First {{ "{:,}".format(n) }} of {{ rows_text(total) }} {%- else -%}First {{ rows_text(n) }}{%- endif -%} {%- endmacro %} {#- TSV or CSV: submit buttons for the shared form, with TSV using formaction -#} {% macro delimited_option(id, name, description, rows, formaction=none) %}