You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7ed0aeb
Browse filesBrowse the repository at this point in the historyBrowse files
Export dialog groups formats that can stream with TSV and CSV
Plugin output formats that accept row_stream now share the form used
by TSV and CSV, so the "Include all rows" and "Expand labels"
options apply to them.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016Bvfq9SBhxPegj4hvi5NF4
Copy file name to clipboardExpand all lines: datasette/templates/_export_dialog.html
+33-14Lines changed: 33 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -12,15 +12,29 @@
12
12
that one row. Otherwise the dialog also offers more JSON shapes, using
13
13
append_querystring.
14
14
Formats from plugins use renderer_options for their label, description
15
-
and which actions to offer. -#}
15
+
and which actions to offer. Those that can stream every row are grouped
16
+
with TSV and CSV, so that "Include all rows" applies to them. -#}
16
17
{% set export_base = export_meta or "data" %}
17
18
{% set export_later = export_rows.later if export_rows else false %}
18
19
{#- "Include all rows" streams every row from the first one, so offer it on
19
20
every later page, and on the first page when CSV would stop short -#}
20
21
{% 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_stream %}
22
+
{#- Formats from plugins that can stream, as (extension, path, options) -#}
23
+
{% set streaming = namespace(formats=[], names=(["TSV"] if url_tsv_path else []) + ["CSV"]) %}
24
+
{% if display_rows %}
25
+
{% for name, url in renderers.items() if name not in ("json", "csv") and not (name == "tsv" and url_tsv_path) %}
26
+
{% set options = (renderer_options or {}).get(name) or {} %}
27
+
{% if options.can_stream %}
28
+
{% set streaming.formats = streaming.formats + [(name, url.split("?")[0], options)] %}
29
+
{% set streaming.names = streaming.names + [options.label or name] %}
30
+
{% endif %}
31
+
{% endfor %}
32
+
{% endif %}
33
+
{% set streaming_extensions = streaming.formats|map("first")|list %}
21
34
{% macro rows_text(n) %}{{ "{:,}".format(n) }} row{{ "" if n == 1 else "s" }}{% endmacro %}
22
35
{#- How many rows an export returns. JSON and plugin formats return the rows
23
-
on this page; TSV and CSV ask for _size=max, starting from this page.
36
+
on this page; TSV, CSV and plugin formats that can stream ("csv" here)
37
+
ask for _size=max, starting from this page.
24
38
Mirrored by rowsLabel() in export-dialog.js. -#}
25
39
{% macro rows_label(kind, rows, id) %}
26
40
{%- set n = rows.page -%}
@@ -41,20 +55,22 @@
41
55
{%- else -%}First {{ rows_text(n) }}{%- endif -%}
42
56
</span>
43
57
{%- endmacro %}
44
-
{#- TSV or CSV: submit buttons for the shared form, with TSV using formaction -#}
{% if export_scope %}<pclass="export-scope" id="export-scope" title="{{ export_scope }}{% if export_scope_description %} {{ export_scope_description }}{% endif %}"><strong>{{ export_scope }}</strong>{% if export_scope_description %} {{ export_scope_description }}{% endif %}</p>{% endif %}
92
-
{% if export_later %}<pclass="export-page-note" id="export-page-note">These exports start from this page, not the first page.{% if csv_stream %} Check “Include all rows” to export every row as {{ "TSV or " if url_tsv_path }}CSV.{% endif %}</p>{% endif %}
108
+
{% if export_later %}<pclass="export-page-note" id="export-page-note">These exports start from this page, not the first page.{% if csv_stream %} Check “Include all rows” to export every row as {{ streaming.names[:-1]|join(", ") }}{{ " or " if streaming.names|length > 1 }}{{ streaming.names[-1] }}.{% endif %}</p>{% endif %}
93
109
{% if display_rows %}
94
-
{#- TSVand CSV share a form, so the options under them apply to both.
95
-
The other formats are in a separate box below, as the options do
96
-
not apply to them. -#}
110
+
{#- TSV, CSV and plugin formats that can stream share a form, so the
111
+
options under them apply to them all. The other formats are in a
112
+
separate box below, as the options do not apply to them. -#}
{% if url_tsv_path %}{{ delimited_option("tsv", "TSV", "Tab-separated values, for pasting into Excel or Google Sheets", export_rows, formaction=url_tsv_path) }}{% endif %}
100
116
{{ delimited_option("csv", "CSV", "Comma-separated values, for spreadsheets and other tools", export_rows) }}
117
+
{% for name, path, options in streaming.formats %}
118
+
{{ delimited_option(name, options.label or name, options.description, export_rows, formaction=path, kind="binary" if options.is_binary else ("webpage" if options.is_webpage else none)) }}
119
+
{% endfor %}
101
120
{% if expandable_columns or csv_stream %}
102
121
<divclass="export-csv-options">
103
122
{% if expandable_columns %}<label><inputtype="checkbox" name="_labels" checked> Expand labels</label>{% endif %}
Copy file name to clipboardExpand all lines: docs/changelog.rst
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@ Unreleased
12
12
- New ``Response.stream(body)`` method for returning a response a chunk at a time from an async iterator of strings or bytes, for example from a :ref:`plugin_register_routes` view. See :ref:`internals_response_stream`.
13
13
- Output renderers can now stream every row of a table or view. A ``render`` function that accepts the new ``row_stream`` argument - an async iterator of rows - and returns ``Response.stream()`` will be sent every row when the URL includes ``?_stream=1``. See :ref:`plugin_register_output_renderer_streaming`. (:issue:`1101`)
14
14
- ``?_stream=1`` now fetches rows in pages of :ref:`setting_max_returned_rows`, 1,000 by default, instead of the default page size of 100. This makes streaming every row of a large table several times faster. A ``?_size=`` in the URL is still respected.
15
+
- The "Export data" dialog now groups plugin formats that can stream with TSV and CSV, so its "Include all rows" option applies to those formats too.
15
16
- CSV and TSV export are now implemented as default output renderers using that mechanism, replacing the previous special case. Plugins can replace either of them by registering a renderer for the ``csv`` or ``tsv`` extension. (:issue:`1062`)
16
17
- **Breaking change**: an "include all rows" export that fails part of the way through, or that reaches the :ref:`setting_max_stream_mb` limit, now drops the connection so the download fails. Previously the error message was written as the last line of the file, which otherwise looked complete.
17
18
- The ``allow_csv_stream`` and ``max_csv_mb`` settings have been renamed to :ref:`setting_allow_stream` and :ref:`setting_max_stream_mb`, since they now apply to every format that can stream. The previous names continue to work.
Copy file name to clipboardExpand all lines: docs/plugin_hooks.rst
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -771,6 +771,8 @@ A table can have far more rows than fit on one page. A ``"render"`` function tha
771
771
772
772
Use ``async for rows in row_stream.pages()`` to receive a list of rows for each page instead of one row at a time. When streaming every row those pages are :ref:`setting_max_returned_rows` rows each, unless the URL sets a different ``?_size=``.
773
773
774
+
The :ref:`Export data dialog <csv_export>` lists formats that accept ``row_stream`` in the same group as TSV and CSV, so that its "Include all rows" and "Expand labels" options apply to them. Like TSV and CSV, their links in the dialog use ``?_size=max``.
775
+
774
776
Datasette's own :ref:`CSV and TSV export <csv_export>` is implemented this way. Some things to be aware of:
775
777
776
778
- ``?_stream=1`` is ignored by formats that do not accept ``row_stream``.
0 commit comments