mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Canned query writes support JSON POST body, refs #880
This commit is contained in:
parent
1552ac931e
commit
896fce228f
3 changed files with 31 additions and 5 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import os
|
||||
import itertools
|
||||
import jinja2
|
||||
import json
|
||||
from urllib.parse import parse_qsl
|
||||
|
||||
from datasette.utils import (
|
||||
check_visibility,
|
||||
|
|
@ -208,7 +210,15 @@ class QueryView(DataView):
|
|||
# Execute query - as write or as read
|
||||
if write:
|
||||
if request.method == "POST":
|
||||
params = await request.post_vars()
|
||||
body = await request.post_body()
|
||||
body = body.decode("utf-8").strip()
|
||||
if body.startswith("{") and body.endswith("}"):
|
||||
params = json.loads(body)
|
||||
# But we want key=value strings
|
||||
for key, value in params.items():
|
||||
params[key] = str(value)
|
||||
else:
|
||||
params = dict(parse_qsl(body, keep_blank_values=True))
|
||||
if canned_query:
|
||||
params_for_query = MagicParameters(params, request, self.ds)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue