mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
New force_https_urls option, refs #333
This commit is contained in:
parent
4e82d0e64d
commit
f24b49a1a8
5 changed files with 44 additions and 11 deletions
|
|
@ -97,10 +97,13 @@ CONFIG_OPTIONS = (
|
|||
Allow .csv?_stream=1 to download all rows (ignoring max_returned_rows)
|
||||
""".strip()),
|
||||
ConfigOption("max_csv_mb", 100, """
|
||||
Maximum size allowed for CSV export in MB. Set 0 to disable this limit.
|
||||
Maximum size allowed for CSV export in MB - set 0 to disable this limit
|
||||
""".strip()),
|
||||
ConfigOption("truncate_cells_html", 2048, """
|
||||
Truncate cells longer than this in HTML table view. Set to 0 to disable.
|
||||
Truncate cells longer than this in HTML table view - set 0 to disable
|
||||
""".strip()),
|
||||
ConfigOption("force_https_urls", False, """
|
||||
Force URLs in API output to always use https:// protocol
|
||||
""".strip()),
|
||||
)
|
||||
DEFAULT_CONFIG = {
|
||||
|
|
|
|||
|
|
@ -142,6 +142,12 @@ class BaseView(RenderMixin):
|
|||
|
||||
return name, expected, None
|
||||
|
||||
def absolute_url(self, request, path):
|
||||
url = urllib.parse.urljoin(request.url, path)
|
||||
if url.startswith("http://") and self.ds.config["force_https_urls"]:
|
||||
url = "https://" + url[len("http://"):]
|
||||
return url
|
||||
|
||||
def get_templates(self, database, table=None):
|
||||
assert NotImplemented
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
from collections import namedtuple
|
||||
import sqlite3
|
||||
import urllib
|
||||
|
||||
|
|
@ -564,9 +563,7 @@ class TableView(RowTableShared):
|
|||
row["value"]
|
||||
),
|
||||
"count": row["count"],
|
||||
"toggle_url": urllib.parse.urljoin(
|
||||
request.url, toggle_path
|
||||
),
|
||||
"toggle_url": self.absolute_url(request, toggle_path),
|
||||
"selected": selected,
|
||||
})
|
||||
except InterruptedError:
|
||||
|
|
@ -650,8 +647,8 @@ class TableView(RowTableShared):
|
|||
added_args["_sort_desc"] = sort_desc
|
||||
else:
|
||||
added_args = {"_next": next_value}
|
||||
next_url = urllib.parse.urljoin(
|
||||
request.url, path_with_replaced_args(request, added_args)
|
||||
next_url = self.absolute_url(
|
||||
request, path_with_replaced_args(request, added_args)
|
||||
)
|
||||
rows = rows[:page_size]
|
||||
|
||||
|
|
@ -702,8 +699,10 @@ class TableView(RowTableShared):
|
|||
):
|
||||
suggested_facets.append({
|
||||
'name': facet_column,
|
||||
'toggle_url': path_with_added_args(
|
||||
request, {'_facet': facet_column}
|
||||
'toggle_url': self.absolute_url(
|
||||
request, path_with_added_args(
|
||||
request, {"_facet": facet_column}
|
||||
)
|
||||
),
|
||||
})
|
||||
except InterruptedError:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue