mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Applied latest Black
This commit is contained in:
parent
2e62282170
commit
10dae61213
12 changed files with 58 additions and 37 deletions
|
|
@ -80,9 +80,9 @@ def search_filters(request, database, table, datasette):
|
||||||
"{fts_pk} in (select rowid from {fts_table} where {fts_table} match {match_clause})".format(
|
"{fts_pk} in (select rowid from {fts_table} where {fts_table} match {match_clause})".format(
|
||||||
fts_table=escape_sqlite(fts_table),
|
fts_table=escape_sqlite(fts_table),
|
||||||
fts_pk=escape_sqlite(fts_pk),
|
fts_pk=escape_sqlite(fts_pk),
|
||||||
match_clause=":search"
|
match_clause=(
|
||||||
if search_mode_raw
|
":search" if search_mode_raw else "escape_fts(:search)"
|
||||||
else "escape_fts(:search)",
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
human_descriptions.append(f'search matches "{search}"')
|
human_descriptions.append(f'search matches "{search}"')
|
||||||
|
|
@ -99,9 +99,11 @@ def search_filters(request, database, table, datasette):
|
||||||
"rowid in (select rowid from {fts_table} where {search_col} match {match_clause})".format(
|
"rowid in (select rowid from {fts_table} where {search_col} match {match_clause})".format(
|
||||||
fts_table=escape_sqlite(fts_table),
|
fts_table=escape_sqlite(fts_table),
|
||||||
search_col=escape_sqlite(search_col),
|
search_col=escape_sqlite(search_col),
|
||||||
match_clause=":search_{}".format(i)
|
match_clause=(
|
||||||
if search_mode_raw
|
":search_{}".format(i)
|
||||||
else "escape_fts(:search_{})".format(i),
|
if search_mode_raw
|
||||||
|
else "escape_fts(:search_{})".format(i)
|
||||||
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
human_descriptions.append(
|
human_descriptions.append(
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ Backported from Python 3.8.
|
||||||
This code is licensed under the Python License:
|
This code is licensed under the Python License:
|
||||||
https://github.com/python/cpython/blob/v3.8.3/LICENSE
|
https://github.com/python/cpython/blob/v3.8.3/LICENSE
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from shutil import copy, copy2, copystat, Error
|
from shutil import copy, copy2, copystat, Error
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -431,9 +431,11 @@ class QueryView(DataView):
|
||||||
display_value = markupsafe.Markup(
|
display_value = markupsafe.Markup(
|
||||||
'<a class="blob-download" href="{}"{}><Binary: {:,} byte{}></a>'.format(
|
'<a class="blob-download" href="{}"{}><Binary: {:,} byte{}></a>'.format(
|
||||||
blob_url,
|
blob_url,
|
||||||
' title="{}"'.format(formatted)
|
(
|
||||||
if "bytes" not in formatted
|
' title="{}"'.format(formatted)
|
||||||
else "",
|
if "bytes" not in formatted
|
||||||
|
else ""
|
||||||
|
),
|
||||||
len(value),
|
len(value),
|
||||||
"" if len(value) == 1 else "s",
|
"" if len(value) == 1 else "s",
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -105,9 +105,11 @@ class IndexView(BaseView):
|
||||||
{
|
{
|
||||||
"name": name,
|
"name": name,
|
||||||
"hash": db.hash,
|
"hash": db.hash,
|
||||||
"color": db.hash[:6]
|
"color": (
|
||||||
if db.hash
|
db.hash[:6]
|
||||||
else hashlib.md5(name.encode("utf8")).hexdigest()[:6],
|
if db.hash
|
||||||
|
else hashlib.md5(name.encode("utf8")).hexdigest()[:6]
|
||||||
|
),
|
||||||
"path": self.ds.urls.database(name),
|
"path": self.ds.urls.database(name),
|
||||||
"tables_and_views_truncated": tables_and_views_truncated,
|
"tables_and_views_truncated": tables_and_views_truncated,
|
||||||
"tables_and_views_more": (len(visible_tables) + len(views))
|
"tables_and_views_more": (len(visible_tables) + len(views))
|
||||||
|
|
|
||||||
|
|
@ -339,9 +339,11 @@ class TableView(DataView):
|
||||||
|
|
||||||
from_sql = "from {table_name} {where}".format(
|
from_sql = "from {table_name} {where}".format(
|
||||||
table_name=escape_sqlite(table_name),
|
table_name=escape_sqlite(table_name),
|
||||||
where=("where {} ".format(" and ".join(where_clauses)))
|
where=(
|
||||||
if where_clauses
|
("where {} ".format(" and ".join(where_clauses)))
|
||||||
else "",
|
if where_clauses
|
||||||
|
else ""
|
||||||
|
),
|
||||||
)
|
)
|
||||||
# Copy of params so we can mutate them later:
|
# Copy of params so we can mutate them later:
|
||||||
from_sql_params = dict(**params)
|
from_sql_params = dict(**params)
|
||||||
|
|
@ -406,10 +408,12 @@ class TableView(DataView):
|
||||||
column=escape_sqlite(sort or sort_desc),
|
column=escape_sqlite(sort or sort_desc),
|
||||||
op=">" if sort else "<",
|
op=">" if sort else "<",
|
||||||
p=len(params),
|
p=len(params),
|
||||||
extra_desc_only=""
|
extra_desc_only=(
|
||||||
if sort
|
""
|
||||||
else " or {column2} is null".format(
|
if sort
|
||||||
column2=escape_sqlite(sort or sort_desc)
|
else " or {column2} is null".format(
|
||||||
|
column2=escape_sqlite(sort or sort_desc)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
next_clauses=" and ".join(next_by_pk_clauses),
|
next_clauses=" and ".join(next_by_pk_clauses),
|
||||||
)
|
)
|
||||||
|
|
@ -772,9 +776,9 @@ class TableView(DataView):
|
||||||
"metadata": metadata,
|
"metadata": metadata,
|
||||||
"view_definition": await db.get_view_definition(table_name),
|
"view_definition": await db.get_view_definition(table_name),
|
||||||
"table_definition": await db.get_table_definition(table_name),
|
"table_definition": await db.get_table_definition(table_name),
|
||||||
"datasette_allow_facet": "true"
|
"datasette_allow_facet": (
|
||||||
if self.ds.setting("allow_facet")
|
"true" if self.ds.setting("allow_facet") else "false"
|
||||||
else "false",
|
),
|
||||||
}
|
}
|
||||||
d.update(extra_context_from_filters)
|
d.update(extra_context_from_filters)
|
||||||
return d
|
return d
|
||||||
|
|
@ -933,9 +937,11 @@ async def display_columns_and_rows(
|
||||||
path_from_row_pks(row, pks, not pks),
|
path_from_row_pks(row, pks, not pks),
|
||||||
column,
|
column,
|
||||||
),
|
),
|
||||||
' title="{}"'.format(formatted)
|
(
|
||||||
if "bytes" not in formatted
|
' title="{}"'.format(formatted)
|
||||||
else "",
|
if "bytes" not in formatted
|
||||||
|
else ""
|
||||||
|
),
|
||||||
len(value),
|
len(value),
|
||||||
"" if len(value) == 1 else "s",
|
"" if len(value) == 1 else "s",
|
||||||
)
|
)
|
||||||
|
|
@ -986,9 +992,9 @@ async def display_columns_and_rows(
|
||||||
"column": column,
|
"column": column,
|
||||||
"value": display_value,
|
"value": display_value,
|
||||||
"raw": value,
|
"raw": value,
|
||||||
"value_type": "none"
|
"value_type": (
|
||||||
if value is None
|
"none" if value is None else str(type(value).__name__)
|
||||||
else str(type(value).__name__),
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
cell_rows.append(Row(cells))
|
cell_rows.append(Row(cells))
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ def extra_css_urls(template, database, table, view_name, columns, request, datas
|
||||||
"database": database,
|
"database": database,
|
||||||
"table": table,
|
"table": table,
|
||||||
"view_name": view_name,
|
"view_name": view_name,
|
||||||
"request_path": request.path
|
"request_path": (
|
||||||
if request is not None
|
request.path if request is not None else None
|
||||||
else None,
|
),
|
||||||
"added": (
|
"added": (
|
||||||
await datasette.get_database().execute("select 3 * 5")
|
await datasette.get_database().execute("select 3 * 5")
|
||||||
).first()[0],
|
).first()[0],
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Tests to ensure certain things are documented.
|
Tests to ensure certain things are documented.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
from datasette import app, utils
|
from datasette import app, utils
|
||||||
from datasette.cli import cli
|
from datasette.cli import cli
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Tests for the datasette.database.Database class
|
Tests for the datasette.database.Database class
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from datasette.database import Database, Results, MultipleValues
|
from datasette.database import Database, Results, MultipleValues
|
||||||
from datasette.utils.sqlite import sqlite3
|
from datasette.utils.sqlite import sqlite3
|
||||||
from datasette.utils import Column
|
from datasette.utils import Column
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Tests for the datasette.app.Datasette class
|
Tests for the datasette.app.Datasette class
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from datasette import Forbidden
|
from datasette import Forbidden
|
||||||
from datasette.app import Datasette, Database
|
from datasette.app import Datasette, Database
|
||||||
from itsdangerous import BadSignature
|
from itsdangerous import BadSignature
|
||||||
|
|
|
||||||
|
|
@ -342,9 +342,11 @@ def test_permissions_debug(app_client):
|
||||||
{
|
{
|
||||||
"action": div.select_one(".check-action").text,
|
"action": div.select_one(".check-action").text,
|
||||||
# True = green tick, False = red cross, None = gray None
|
# True = green tick, False = red cross, None = gray None
|
||||||
"result": None
|
"result": (
|
||||||
if div.select(".check-result-no-opinion")
|
None
|
||||||
else bool(div.select(".check-result-true")),
|
if div.select(".check-result-no-opinion")
|
||||||
|
else bool(div.select(".check-result-true"))
|
||||||
|
),
|
||||||
"used_default": bool(div.select(".check-used-default")),
|
"used_default": bool(div.select(".check-used-default")),
|
||||||
}
|
}
|
||||||
for div in check_divs
|
for div in check_divs
|
||||||
|
|
|
||||||
|
|
@ -279,9 +279,11 @@ def test_paginate_compound_keys_with_extra_filters(app_client):
|
||||||
"_sort_desc=sortable_with_nulls",
|
"_sort_desc=sortable_with_nulls",
|
||||||
lambda row: (
|
lambda row: (
|
||||||
1 if row["sortable_with_nulls"] is None else 0,
|
1 if row["sortable_with_nulls"] is None else 0,
|
||||||
-row["sortable_with_nulls"]
|
(
|
||||||
if row["sortable_with_nulls"] is not None
|
-row["sortable_with_nulls"]
|
||||||
else 0,
|
if row["sortable_with_nulls"] is not None
|
||||||
|
else 0
|
||||||
|
),
|
||||||
row["content"],
|
row["content"],
|
||||||
),
|
),
|
||||||
"sorted by sortable_with_nulls descending",
|
"sorted by sortable_with_nulls descending",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Tests for various datasette helper functions.
|
Tests for various datasette helper functions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from datasette.app import Datasette
|
from datasette.app import Datasette
|
||||||
from datasette import utils
|
from datasette import utils
|
||||||
from datasette.utils.asgi import Request
|
from datasette.utils.asgi import Request
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue