mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
New datasette.urls URL builders, refs #904
This commit is contained in:
parent
c440ffc65a
commit
310c3a3e05
11 changed files with 64 additions and 44 deletions
|
|
@ -1,7 +1,5 @@
|
|||
import asyncio
|
||||
import csv
|
||||
import itertools
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
import urllib
|
||||
|
|
@ -16,27 +14,22 @@ from datasette.utils import (
|
|||
InvalidSql,
|
||||
LimitedWriter,
|
||||
call_with_supported_arguments,
|
||||
is_url,
|
||||
path_with_added_args,
|
||||
path_with_removed_args,
|
||||
path_with_format,
|
||||
resolve_table_and_format,
|
||||
sqlite3,
|
||||
to_css_class,
|
||||
HASH_LENGTH,
|
||||
)
|
||||
from datasette.utils.asgi import (
|
||||
AsgiStream,
|
||||
AsgiWriter,
|
||||
Forbidden,
|
||||
NotFound,
|
||||
Request,
|
||||
Response,
|
||||
)
|
||||
|
||||
ureg = pint.UnitRegistry()
|
||||
|
||||
HASH_LENGTH = 7
|
||||
|
||||
|
||||
class DatasetteError(Exception):
|
||||
def __init__(
|
||||
|
|
@ -99,14 +92,6 @@ class BaseView:
|
|||
else:
|
||||
raise Forbidden(action)
|
||||
|
||||
def database_url(self, database):
|
||||
db = self.ds.databases[database]
|
||||
base_url = self.ds.config("base_url")
|
||||
if self.ds.config("hash_urls") and db.hash:
|
||||
return "{}{}-{}".format(base_url, database, db.hash[:HASH_LENGTH])
|
||||
else:
|
||||
return "{}{}".format(base_url, database)
|
||||
|
||||
def database_color(self, database):
|
||||
return "ff0000"
|
||||
|
||||
|
|
@ -132,7 +117,6 @@ class BaseView:
|
|||
template_context = {
|
||||
**context,
|
||||
**{
|
||||
"database_url": self.database_url,
|
||||
"database_color": self.database_color,
|
||||
"select_templates": [
|
||||
"{}{}".format(
|
||||
|
|
|
|||
|
|
@ -348,7 +348,7 @@ class QueryView(DataView):
|
|||
pass
|
||||
if allow_execute_sql and is_validated_sql and ":_" not in sql:
|
||||
edit_sql_url = (
|
||||
self.database_url(database)
|
||||
self.ds.urls.database(database)
|
||||
+ "?"
|
||||
+ urlencode(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ class IndexView(BaseView):
|
|||
"color": db.hash[:6]
|
||||
if db.hash
|
||||
else hashlib.md5(name.encode("utf8")).hexdigest()[:6],
|
||||
"path": self.database_url(name),
|
||||
"path": self.ds.urls.database(name),
|
||||
"tables_and_views_truncated": tables_and_views_truncated,
|
||||
"tables_and_views_more": (len(visible_tables) + len(views))
|
||||
> TRUNCATE_AT,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue