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