mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Ran black source formatting tool against new views/ and app.py
This commit is contained in:
parent
1f69269fe9
commit
3686385551
5 changed files with 737 additions and 627 deletions
|
|
@ -1,13 +1,12 @@
|
|||
from .base import RenderMixin, HASH_LENGTH
|
||||
from sanic import response
|
||||
from datasette.utils import (
|
||||
CustomJSONEncoder,
|
||||
)
|
||||
from datasette.utils import CustomJSONEncoder
|
||||
from datasette.version import __version__
|
||||
import json
|
||||
|
||||
|
||||
class IndexView(RenderMixin):
|
||||
|
||||
def __init__(self, datasette):
|
||||
self.ds = datasette
|
||||
self.files = datasette.files
|
||||
|
|
@ -17,40 +16,38 @@ class IndexView(RenderMixin):
|
|||
async def get(self, request, as_json):
|
||||
databases = []
|
||||
for key, info in sorted(self.ds.inspect().items()):
|
||||
tables = [t for t in info['tables'].values() if not t['hidden']]
|
||||
hidden_tables = [t for t in info['tables'].values() if t['hidden']]
|
||||
tables = [t for t in info["tables"].values() if not t["hidden"]]
|
||||
hidden_tables = [t for t in info["tables"].values() if t["hidden"]]
|
||||
database = {
|
||||
'name': key,
|
||||
'hash': info['hash'],
|
||||
'path': '{}-{}'.format(key, info['hash'][:HASH_LENGTH]),
|
||||
'tables_truncated': sorted(
|
||||
tables,
|
||||
key=lambda t: t['count'],
|
||||
reverse=True
|
||||
)[:5],
|
||||
'tables_count': len(tables),
|
||||
'tables_more': len(tables) > 5,
|
||||
'table_rows_sum': sum(t['count'] for t in tables),
|
||||
'hidden_table_rows_sum': sum(t['count'] for t in hidden_tables),
|
||||
'hidden_tables_count': len(hidden_tables),
|
||||
'views_count': len(info['views']),
|
||||
"name": key,
|
||||
"hash": info["hash"],
|
||||
"path": "{}-{}".format(key, info["hash"][:HASH_LENGTH]),
|
||||
"tables_truncated": sorted(
|
||||
tables, key=lambda t: t["count"], reverse=True
|
||||
)[
|
||||
:5
|
||||
],
|
||||
"tables_count": len(tables),
|
||||
"tables_more": len(tables) > 5,
|
||||
"table_rows_sum": sum(t["count"] for t in tables),
|
||||
"hidden_table_rows_sum": sum(t["count"] for t in hidden_tables),
|
||||
"hidden_tables_count": len(hidden_tables),
|
||||
"views_count": len(info["views"]),
|
||||
}
|
||||
databases.append(database)
|
||||
if as_json:
|
||||
headers = {}
|
||||
if self.ds.cors:
|
||||
headers['Access-Control-Allow-Origin'] = '*'
|
||||
headers["Access-Control-Allow-Origin"] = "*"
|
||||
return response.HTTPResponse(
|
||||
json.dumps(
|
||||
{db['name']: db for db in databases},
|
||||
cls=CustomJSONEncoder
|
||||
),
|
||||
content_type='application/json',
|
||||
json.dumps({db["name"]: db for db in databases}, cls=CustomJSONEncoder),
|
||||
content_type="application/json",
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
else:
|
||||
return self.render(
|
||||
['index.html'],
|
||||
["index.html"],
|
||||
databases=databases,
|
||||
metadata=self.ds.metadata,
|
||||
datasette_version=__version__,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue