Commit graph

204 commits

Author SHA1 Message Date
Simon Willison
e7151ccccf Index page no longer uses inspect data - refs #420
Also introduced a mechanism whereby table counts are calculated against a time limit
but immutable databases have their table counts calculated on server startup.
2019-05-01 17:39:39 -07:00
Simon Willison
669fa21a71 Include request duration in traces 2019-05-01 16:27:14 -07:00
Russ Garrett
cf406c0754 New plugin hook: register_output_renderer hook (#441)
Thanks @russss!

* Add register_output_renderer hook

This changeset refactors out the JSON renderer and then adds a hook and
dispatcher system to allow custom output renderers to be registered.

The CSV output renderer is untouched because supporting streaming
renderers through this system would be significantly more complex, and
probably not worthwhile.

We can't simply allow hooks to be called at request time because we need
a list of supported file extensions when the request is being routed in
order to resolve ambiguous database/table names. So, renderers need to
be registered at startup.

I've tried to make this API independent of Sanic's request/response
objects so that this can remain stable during the switch to ASGI. I'm
using dictionaries to keep it simple and to make adding additional
options in the future easy.

Fixes #440
2019-05-01 16:01:56 -07:00
Simon Willison
e4e73a537a Test for ?_trace=1, refs #435 2019-04-21 10:46:56 -07:00
Simon Willison
9c77e6e355 Support multiple filters of the same type
Closes #288
2019-04-15 16:44:17 -07:00
Simon Willison
583b22aa28 New ?column__date=yyyy-mm-dd filter 2019-04-15 15:54:54 -07:00
Simon Willison
1c6649b19b New colname__in=x,y,z filter, closes #433 2019-04-15 15:43:22 -07:00
Simon Willison
2c19a27d15 Documentation for filters, plus new documentation unit test
https://simonwillison.net/2018/Jul/28/documentation-unit-tests/
2019-04-15 15:41:11 -07:00
Simon Willison
6da567dda9 Extract and refactor filters into filters.py
This will help in implementing __in as a filter, refs #433
2019-04-15 14:51:20 -07:00
Simon Willison
bc6a9b4564
?_where= parameter on table views, closes #429
From pull request #430
2019-04-12 18:37:22 -07:00
Simon Willison
e11cb4c664 Persist show/hide state better, closes #425 2019-04-11 22:00:47 -07:00
Simon Willison
db74cf0144 ?_fts_table= and ?_fts_pk= arguments, closes #428 2019-04-11 21:21:17 -07:00
Simon Willison
78e45ead4d New ?tags__arraycontains=tag lookup against JSON fields
Part one of supporting facet-by-JSON-array, refs #359
2019-04-10 08:27:52 -07:00
Simon Willison
53bf875483 expand_foreign_keys() no longer uses inspect, refs #420 2019-04-06 19:56:07 -07:00
Simon Willison
97331f3435 sortable_columns_for_table() no longer uses inspect()
Refs #420
2019-04-06 18:58:51 -07:00
Simon Willison
468c6fd953 DatabaseDownload no longer uses .inspect(), refs #420 2019-03-31 19:04:17 -07:00
Simon Willison
7d0f668556 .resolve_db_name() and .execute() work without inspect
Refs #420
2019-03-31 16:51:52 -07:00
Simon Willison
0209a0a344 table_exists() now uses async SQL, refs #420 2019-03-31 11:02:22 -07:00
Simon Willison
6f6d0ff2b4
URL hashing is now off by default - closes #418
Prior to this commit Datasette would calculate the content hash of every
database and redirect to a URL containing that hash, like so:

    https://v0-27.datasette.io/fixtures => https://v0-27.datasette.io/fixtures-dd88475

This assumed that all databases were opened in immutable mode and were not
expected to change.

This will be changing as a result of #419 - so this commit takes the first step
in implementing that change by changing this default behaviour. Datasette will
now only redirect hash-free URLs under two circumstances:

* The new `hash_urls` config option is set to true (it defaults to false).
* The user passes `?_hash=1` in the URL
2019-03-17 15:55:04 -07:00
Simon Willison
afe9aa3ae0 show/hide link for SQL on custom query page
Closes #415
2019-03-14 22:22:35 -07:00
Simon Willison
2855667908 Fix for test failure with Click 7.0 2019-03-14 22:00:13 -07:00
Simon Willison
9743e1d91b Support for :memory: databases
If you start Datasette with no files, it will connect to :memory: instead.

When starting it with files you can add --memory to also get a :memory: database.
2019-03-14 20:54:42 -07:00
Simon Willison
bf6b0f918d about and about_url metadata options 2019-03-14 20:54:42 -07:00
Simon Willison
4462a5ab28 Show size of database file next to download link, closes #172 2019-02-05 20:58:29 -08:00
Simon Willison
195a5b3634
Heroku --include-vcs-ignore (#407)
Means `datasette publish heroku` can work under Travis, unlike this failure:

https://travis-ci.org/simonw/fivethirtyeight-datasette/builds/488047550

```
2.25s$ datasette publish heroku fivethirtyeight.db -m metadata.json -n fivethirtyeight-datasette
tar: unrecognized option '--exclude-vcs-ignores'
Try 'tar --help' or 'tar --usage' for more information.
 ▸    Command failed: tar cz -C /tmp/tmpuaxm7i8f --exclude-vcs-ignores --exclude
 ▸    .git --exclude .gitmodules . >
 ▸    /tmp/f49440e0-1bf3-4d3f-9eb0-fbc2967d1fd4.tar.gz
 ▸    tar: unrecognized option '--exclude-vcs-ignores'
 ▸    Try 'tar --help' or 'tar --usage' for more information.
 ▸    
The command "datasette publish heroku fivethirtyeight.db -m metadata.json -n fivethirtyeight-datasette" exited with 0.
```

The fix for that issue is to call the heroku command like this:

    heroku builds:create -a app_name --include-vcs-ignore
2019-02-05 20:15:46 -08:00
Simon Willison
b5dd83981a Export option: _shape=array&_nl=on for newline-delimited JSON 2019-01-27 17:40:23 -08:00
Simon Willison
c3a78eb05c app_client() fixture doesn't need to take **kwargs 2019-01-13 14:23:44 -08:00
Simon Willison
8ce7866312 compile_options output in /-/versions, closes #396 2019-01-10 16:44:50 -08:00
Simon Willison
996e8822d2 Fix CSV export hidden form fields, closes #393 2019-01-02 18:43:56 -08:00
Simon Willison
a2bfcfc1b1
Fix some regex DeprecationWarnings (#392) 2018-12-28 18:22:27 -08:00
Simon Willison
3de8fac1d3
New make_app_client() pattern
Because next version of pytest discourages calling fixture factories as functions
2018-11-20 09:46:47 -08:00
Simon Willison
b7257a21bf
Fix json.loads in Python 3.5
3.5 requires a str, not a bytes

https://travis-ci.org/simonw/datasette/jobs/421660555
2018-08-28 17:55:30 +01:00
Simon Willison
b7c6a9f9bd
extra_css_urls(template, database, table, datasette)
The extra_css_urls and extra_js_urls hooks now take additional optional
parameters.

Also refactored them out of the Datasette class and into RenderMixin.

Plus improved plugin documentation to explicitly list parameters.
2018-08-28 11:56:57 +01:00
Simon Willison
2e836f72d9
render_cell(value, column, table, database, datasette)
The render_cell plugin hook previously was only passed value.

It is now passed (value, column, table, database, datasette).
2018-08-28 03:03:01 -07:00
Simon Willison
5cf0c6c91c
New plugin hook: extra_body_script 2018-08-28 02:02:49 -07:00
Simon Willison
0a14a4846b
Added plugin_config() method 2018-08-28 01:35:21 -07:00
Simon Willison
aae49fef3b
Import pysqlite3 if available, closes #360 (#361) 2018-08-15 17:58:56 -07:00
Simon Willison
fe5b6ea95a
Hide 'view and edit SQL' if config.allow_sql turned off 2018-08-05 20:17:17 -07:00
Simon Willison
5629aaca67
sortable_columns also now works with views 2018-08-05 17:29:23 -07:00
Simon Willison
4ac9132240
render_cell(value) plugin hook, closes #352
New plugin hook for customizing the way cells values are rendered in HTML.

The first full example of this hook in use is https://github.com/simonw/datasette-json-html
2018-08-04 17:14:56 -07:00
Simon Willison
295d005ca4
Renamed variable, since docs are not written in Markdown 2018-07-27 21:56:51 -07:00
Simon Willison
8128497b79
Only run documented_views() fixture once per session
Speeds up tests, because previously it ran once per view class.
2018-07-27 21:49:20 -07:00
Simon Willison
788a542d3c
Docs for IndexView, TableView, RowView, closes #299
Also removed xfail from test_view_classes_are_documented, so any future *View
classes that are added without documentation will cause the tests to fail.
2018-07-27 21:21:42 -07:00
Simon Willison
e8625695a3
xfail documentation unit tests for view classes, refs #299
More documentation unit tests. These ones check that every single **View class
imported into the datasette/app.py module are covered by our documentation.

Just one problem: they aren't documented yet. So I'm using the xfail pytest
decorator to mark these tests as allowed-to-fail. When you run the test suite
you now get a report of how many views still need to be documented, but it
doesn't fail the tests.

The output looks something like this:

    $ pytest tests/test_docs.py
    collected 31 items

    tests/test_docs.py ..........................XXXxx.                [100%]

    ============ 26 passed, 2 xfailed, 3 xpassed in 1.06 seconds ============

Once I have documented all the views I will remove the xfail so any future
views that are added without documentation will cause a test failure.

We can detect that a view is documented by looking for ReST label in the docs,
for example:

    .. _IndexView:

Some view classes can be used to power multiple URLs - the JsonDataView class
for example is used to power /-/metadata and /-/config and /-/plugins

In this case, the second part of the label can indicate the variety of page, e.g:

    .. _JsonDataView_metadata:

The test will pass as long as there is at least one label that starts with
_JsonDataView.
2018-07-27 20:13:26 -07:00
Simon Willison
3b68314d8f
Unit tests for publish now/heroku - closes #348 2018-07-25 22:45:47 -07:00
Simon Willison
dbbe707841
publish_subcommand hook + default plugins mechanism, used for publish heroku/now (#349)
This change introduces a new plugin hook, publish_subcommand, which can be
used to implement new subcommands for the "datasette publish" command family.

I've used this new hook to refactor out the "publish now" and "publish heroku"
implementations into separate modules. I've also added unit tests for these
two publishers, mocking the subprocess.call and subprocess.check_output
functions.

As part of this, I introduced a mechanism for loading default plugins. These
are defined in the new "default_plugins" list inside datasette/app.py

Closes #217 (Plugin support for datasette publish)
Closes #348 (Unit tests for "datasette publish")
Refs #14, #59, #102, #103, #146, #236, #347
2018-07-25 22:15:59 -07:00
Simon Willison
3ac21c7498
Unit test confirming all plugin hooks are documented 2018-07-25 21:09:59 -07:00
Simon Willison
ba64cfb4bc
Fix for Python 3.5
https://stackoverflow.com/a/42694113/6083
2018-07-25 10:20:56 -07:00
Simon Willison
9b85c59907
Removed unnecessary print statements from tests 2018-07-24 09:04:06 -07:00
Simon Willison
74ad3ff4af
Ensure --help examples in docs are always up to date, closes #336
Unit tests now check that docs/*.txt help examples are all up-to-date.

I ran into a problem here in that the terminal_width needed to be more
accurately defined - so I replaced update-docs-help.sh with update-docs-
help.py which hard-codes the terminal width.
2018-07-24 09:01:23 -07:00