mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Replaced sanic.request.RequestParameters
This commit is contained in:
parent
1e0998ed2d
commit
979ae4f916
2 changed files with 15 additions and 3 deletions
|
|
@ -741,3 +741,16 @@ def format_bytes(bytes):
|
||||||
return "{} {}".format(int(current), unit)
|
return "{} {}".format(int(current), unit)
|
||||||
else:
|
else:
|
||||||
return "{:.1f} {}".format(current, unit)
|
return "{:.1f} {}".format(current, unit)
|
||||||
|
|
||||||
|
|
||||||
|
class RequestParameters(dict):
|
||||||
|
def get(self, name, default=None):
|
||||||
|
"Return first value in the list, if available"
|
||||||
|
try:
|
||||||
|
return super().get(name)[0]
|
||||||
|
except KeyError:
|
||||||
|
return default
|
||||||
|
|
||||||
|
def getlist(self, name, default=None):
|
||||||
|
"Return full list"
|
||||||
|
return super().get(name, default)
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ import json
|
||||||
|
|
||||||
import jinja2
|
import jinja2
|
||||||
from sanic.exceptions import NotFound
|
from sanic.exceptions import NotFound
|
||||||
from sanic.request import RequestParameters
|
|
||||||
|
|
||||||
from datasette.plugins import pm
|
from datasette.plugins import pm
|
||||||
from datasette.utils import (
|
from datasette.utils import (
|
||||||
CustomRow,
|
CustomRow,
|
||||||
QueryInterrupted,
|
QueryInterrupted,
|
||||||
|
RequestParameters,
|
||||||
append_querystring,
|
append_querystring,
|
||||||
compound_keys_after_sql,
|
compound_keys_after_sql,
|
||||||
escape_sqlite,
|
escape_sqlite,
|
||||||
|
|
@ -219,8 +219,7 @@ class TableView(RowTableShared):
|
||||||
if is_view:
|
if is_view:
|
||||||
order_by = ""
|
order_by = ""
|
||||||
|
|
||||||
# We roll our own query_string decoder because by default Sanic
|
# Ensure we don't drop anything with an empty value e.g. ?name__exact=
|
||||||
# drops anything with an empty value e.g. ?name__exact=
|
|
||||||
args = RequestParameters(
|
args = RequestParameters(
|
||||||
urllib.parse.parse_qs(request.query_string, keep_blank_values=True)
|
urllib.parse.parse_qs(request.query_string, keep_blank_values=True)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue