Commit graph

116 commits

Author SHA1 Message Date
Simon Willison
404fa2252b
datasette publish/package --install option, closes #223
Allows you to specify one or more additional packages to be installed,
useful for deploying plugins.
2018-04-18 07:55:36 -07:00
Russ Garrett
b231d4243d Correct escaping for HTML display of row links 2018-04-17 18:13:02 -07:00
Simon Willison
b2955d9065
New --plugins-dir=plugins/ option (#212)
* New --plugins-dir=plugins/ option

New option causing Datasette to load and evaluate all of the Python files in
the specified directory and register any plugins that are defined in those
files.

This new option is available for the following commands:

    datasette serve mydb.db --plugins-dir=plugins/
    datasette publish now/heroku mydb.db --plugins-dir=plugins/
    datasette package mydb.db --plugins-dir=plugins/

* Unit tests for --plugins-dir=plugins/

Closes #211
2018-04-15 22:22:01 -07:00
Russ Garrett
ab85605c61
Support units in filters 2018-04-14 11:43:35 +01:00
Russ Garrett
d08a133140 Hide Spatialite system tables
They were getting on my nerves.
2018-04-12 14:34:47 -07:00
Simon Willison
cca8bf36fe
Allow explain select / explain query plan select
Closes #201
2018-04-12 14:32:47 -07:00
Simon Willison
c1d37fdf2b Fixed bug with human filter description, refs #189
We were showing this:

    201 rows where sorted by sortable_with_nulls

We now show this:

    201 rows sorted by sortable_with_nulls
2018-04-08 22:10:22 -07:00
Simon Willison
9f2ec39fbc Current sort order now reflected in human filter description
Plus renamed human_description to human_description_en

Refs #189
2018-04-08 22:10:22 -07:00
Simon Willison
f3a3820ff5 _sort and _sort_desc parameters for table views
Allows for paginated sorted results based on a specified column.

Refs #189
2018-04-08 22:10:22 -07:00
Simon Willison
0abd3abacb
New ?_shape=objects/object/lists param for JSON API (#192)
New _shape= parameter replacing old .jsono extension

Now instead of this:

	/database/table.jsono

We use the _shape parameter like this:

	/database/table.json?_shape=objects

Also introduced a new _shape called 'object' which looks like this:

	/database/table.json?_shape=object

Returning an object for the rows key:

	...
	"rows": {
		"pk1": {
			...
		},
		"pk2": {
			...
		}
	}

Refs #122
2018-04-03 07:52:54 -07:00
Simon Willison
8f0d44d646
escape_sqlite_table_name => escape_sqlite, handles reserved words
It can be used for column names as well as table names.

Reserved word list from https://www.sqlite.org/lang_keywords.html
2018-04-03 06:40:49 -07:00
Simon Willison
7365c3f51c
Compound primary key _next= now plays well with extra filters
Closes #190
2018-03-29 23:26:22 -07:00
Simon Willison
31f63d1672
Fixed bug with keyset pagination over compound primary keys
Closes #190
2018-03-29 22:11:02 -07:00
Tony Hirst
3a56a2cd7e Add metadata, if it exists, to heroku temp dir (#178) 2018-01-14 13:05:16 -08:00
Simon Willison
68a34bc222
Deploy to Heroku with Python 3.6.3
Heroku deploys are currently showing the following warning:

    The latest version of Python 3 is python-3.6.3 (you are using python-3.6.2, which is unsupported).
    We recommend upgrading by specifying the latest version (python-3.6.3).
2017-12-09 18:01:17 -08:00
Simon Willison
c195ee4d46
package and publish commands now accept --static and --template-dir
Example usage:

    datasette package --static css:extra-css/ --static js:extra-js/ \
    	sf-trees.db --template-dir templates/ --tag sf-trees --branch master

This creates a local Docker image that includes copies of the templates/,
extra-css/ and extra-js/ directories. You can then run it like this:

	docker run -p 8001:8001 sf-trees

For publishing to Zeit now:

	datasette publish now --static css:extra-css/ --static js:extra-js/ \
		sf-trees.db --template-dir templates/ --name sf-trees --branch master

Example: https://sf-trees-wbihszoazc.now.sh/sf-trees-02c8ef1/Street_Tree_List

For publishing to Heroku:

	datasette publish heroku --static css:extra-css/ --static js:extra-js/ \
		sf-trees.db --template-dir templates/ --branch master

Closes #157, #160
2017-12-09 10:28:49 -08:00
Simon Willison
61e3c5a1e9
Removed rogue print statement, refs #141 2017-12-08 08:08:00 -08:00
Simon Willison
cbfd6b745e
Publish should now work if /tmp is on different device
Fixes #141
2017-12-08 08:06:24 -08:00
Simon Willison
0539905806
Renamed "datasette build" command to "datasette inspect"
Closes #130
2017-12-07 08:57:31 -08:00
Simon Willison
709f4f2798
Fixed bug with detecting FTS tables
Closes #135
2017-12-06 20:54:37 -08:00
Simon Willison
0cfd7ce59d
Allow WITH query (previously we required SELECT at start)
Fixes #161
2017-12-03 20:51:31 -08:00
Simon Willison
8ab3a169d4
CSS styling hooks as classes on the body
Refs #153

Every template now gets CSS classes in the body designed to support custom
styling.

The index template (the top level page at /) gets this:

    <body class="index">

The database template (/dbname/) gets this:

    <body class="db db-dbname">

The table template (/dbname/tablename) gets:

    <body class="table db-dbname table-tablename">

The row template (/dbname/tablename/rowid) gets:

    <body class="row db-dbname table-tablename">

The db-x and table-x classes use the database or table names themselves IF
they are valid CSS identifiers. If they aren't, we strip any invalid
characters out and append a 6 character md5 digest of the original name, in
order to ensure that multiple tables which resolve to the same stripped
character version still have different CSS classes.

Some examples (extracted from the unit tests):

    "simple" => "simple"
    "MixedCase" => "MixedCase"
    "-no-leading-hyphens" => "no-leading-hyphens-65bea6"
    "_no-leading-underscores" => "no-leading-underscores-b921bc"
    "no spaces" => "no-spaces-7088d7"
    "-" => "336d5e"
    "no $ characters" => "no--characters-59e024"
2017-11-29 23:09:54 -08:00
Simon Willison
b67890d15d
Auto-link column values that look like URLs
Refs #153
2017-11-29 09:05:24 -08:00
Simon Willison
c5c923d93c
Don't incorrectly detect VIEWs as supporting FTS 2017-11-24 14:51:00 -08:00
Simon Willison
a802cbee74
Search now applies to current filters
Combined search into the same form as filters.

Closes #133
2017-11-24 14:29:54 -08:00
Simon Willison
b450778391
Added column__not=blah filter
Closes #148
2017-11-23 14:09:50 -08:00
Simon Willison
ef3eacf622
Select option for removing filters 2017-11-23 12:32:54 -08:00
Simon Willison
72e328dccf
Removed rogue print statement 2017-11-22 20:40:15 -08:00
Simon Willison
82c20ea36e
Added '- pick a column -' as first option 2017-11-22 20:39:53 -08:00
Simon Willison
0071b5d6f5
Added UI for editing table filters
Refs #86
2017-11-22 20:33:55 -08:00
Simon Willison
53534b6e9d
Even more complicated redirect scheme
This:

    ?_filter_column_1=name&_filter_op_1=contains&_filter_value_1=hello
    &_filter_column_2=age&_filter_op_2=gte&_filter_value_2=12

Now redirects to this:

    ?name__contains=hello&age__gte=12

This is needed for the filter editing interface, refs #86
2017-11-22 20:03:46 -08:00
Simon Willison
fb505de11c
Back-ported format strings for compatibility with Py 3.5
Also fixed a encoding error where Heroku --json return needs to be treated as UTF8
2017-11-22 09:42:29 -08:00
Jacob Kaplan-Moss
de42240afd Some bug fixes. 2017-11-21 10:51:58 -08:00
Jacob Kaplan-Moss
75450abbe8 Merge branch 'master' into publish-heroku 2017-11-21 10:19:42 -08:00
Simon Willison
0331666e34
?_search=x now works directly against fts virtual table
Closes #135
2017-11-19 22:18:07 -08:00
Simon Willison
b4e6211a97
Refactored filter logic and added human descriptions - refs #86 2017-11-19 22:03:24 -08:00
Simon Willison
386fb11d42
?_filter_column=col&_filter_op=op&_filter_value=value redirect
Part of implementing the filters UI (refs #86) - the following:

    /trees/Trees?_filter_column=SiteOrder&_filter_op=gt&_filter_value=2

Now redirects to this;

    /trees/Trees?SiteOrder__gt=2
2017-11-19 12:25:29 -08:00
Simon Willison
ddc808f387
Added --build=master option to datasette publish and package
The `datasette publish` and `datasette package` commands both now accept an
optional `--build` argument. If provided, this can be used to specify a branch
published to GitHub that should be built into the container.

This makes it easier to test code that has not yet been officially released to
PyPI, e.g.:

    datasette publish now mydb.db --branch=master
2017-11-19 10:20:17 -08:00
Simon Willison
eed6a0fe36
Implemented ?_search=XXX + UI if a FTS table is detected
Closes #131
2017-11-19 08:59:26 -08:00
Jacob Kaplan-Moss
54d58ef690 Merge branch 'master' into publish-heroku 2017-11-17 13:36:50 -08:00
Jacob Kaplan-Moss
6eb23d2143 Moved datasette build to a post_compile hook. 2017-11-17 12:09:01 -08:00
Simon Willison
0b702f3679 Fixed weird edge-case with foreign key detection
It turns out it is possible for a SQLite table to define a foreign key
relationship to a table that does not actually exist

We should still be able to handle these databases.
2017-11-17 08:18:26 -08:00
Simon Willison
45e502aace Added unit tests for inspect() foreign key detection
Used them to fix a bug with it.

Refs #85
2017-11-17 08:08:11 -08:00
Ray N
ed2b3f25be add support for ?field__isnull=1 (#107)
* add support for ?field__isnull=1

* Add unit test and conditional formatting for ?field__isnull
2017-11-17 05:29:22 -08:00
Simon Willison
a4af532a31 Include foreign key info in inspect() output
Refs #85
2017-11-15 17:34:32 -08:00
Jacob Kaplan-Moss
f48cb705d8 Initial cut at datasette publish heroku
Rather gross, but proves that it works.
2017-11-15 11:53:00 -08:00
Simon Willison
f45ca30f91 Fixed bug with datasette package --metadata
Closes #84
2017-11-14 21:18:29 -08:00
Simon Willison
ea183b2ae3 Default to 127.0.0.1 not 0.0.0.0
Closes #98
2017-11-14 21:08:46 -08:00
Simon Willison
7fe1e8b482 Added extra metadata options to publish and package commands
You can now run these commands like so:

    datasette now publish mydb.db \
        --title="My Title" \
        --source="Source" \
        --source_url="http://www.example.com/" \
        --license="CC0" \
        --license_url="https://creativecommons.org/publicdomain/zero/1.0/"

This will write those values into the metadata.json that is packaged with the
app. If you also pass --metadata= that file will be updated with the extra
values before being written into the Docker image.

Closes #92
2017-11-14 21:02:11 -08:00
Simon Willison
0b8c1b0a6d Test for sql_time_limit_ms + sqlite_functions mechanism
Added a unit test for the sql_time_limit_ms option.

To test this, I needed to add a custom SQLite sleep() function. I've added a
simple mechanism to the Datasette class for registering custom functions.

I also had to modify the sqlite_timelimit() function. It makes use of a magic
value, N, which is the number of SQLite virtual machine instructions that
should execute in between calls to my termination decision function.

The value of N was not finely grained enough for my test to work - so I've
added logic that says that if the time limit is less than 50ms, N is set to 1.
This got the tests working.

Refs #95
2017-11-14 18:43:34 -08:00