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 dcc61cf
Browse filesBrowse the repository at this point in the historyBrowse files
Resolves conflicts with the 1.0a43 release: the export dialog uses the
renamed default_allow_stream setting, and the two changelog entries move
to the Unreleased section.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.default_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
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,8 @@ Unreleased
11
11
12
12
- **Backwards incompatible:** the ``format_bytes()`` function is no longer available in templates, and ``datasette.utils.format_bytes()`` has been removed. Custom templates that call ``{{ format_bytes(size) }}`` should use Jinja's built-in `filesizeformat <https://jinja.palletsprojects.com/en/stable/templates/#jinja-filters.filesizeformat>`__ filter instead: ``{{ size|filesizeformat }}``. (:issue:`1841`)
13
13
- File sizes shown on the database page and in the tooltips for binary values now use decimal units, where 1 MB is 1,000,000 bytes, matching the sizes already shown on the homepage. They previously used 1 MB to mean 1,048,576 bytes, so a 5,242,880 byte database that was displayed as ``5.0 MB`` is now displayed as ``5.2 MB``.
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.
Copy file name to clipboardExpand all lines: docs/plugin_hooks.rst
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -769,7 +769,9 @@ A table can have far more rows than fit on one page. A ``"render"`` function tha
769
769
770
770
``row_stream`` yields the rows on the current page. If the URL includes ``?_stream=1`` it carries on past the end of that page, fetching one page at a time, until it has yielded every row in the table or view. Your function does not need to know which of those is happening.
771
771
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.
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
+
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``.
773
775
774
776
Datasette's own :ref:`CSV and TSV export <csv_export>` is implemented this way. Some things to be aware of:
0 commit comments