kopia lustrzana https://github.com/simonw/datasette
Fixed remaining places that needed datasette.urls, closes #1025
rodzic
0d1763fb2f
commit
091441a444
|
@ -158,7 +158,7 @@ CONFIG_OPTIONS = (
|
|||
False,
|
||||
"Allow display of template debug information with ?_context=1",
|
||||
),
|
||||
ConfigOption("base_url", "/", "Datasette URLs should use this base"),
|
||||
ConfigOption("base_url", "/", "Datasette URLs should use this base path"),
|
||||
)
|
||||
|
||||
DEFAULT_CONFIG = {option.name: option.default for option in CONFIG_OPTIONS}
|
||||
|
|
|
@ -457,10 +457,12 @@ def serve(
|
|||
|
||||
# Start the server
|
||||
if root:
|
||||
url = "http://{}:{}/-/auth-token?token={}".format(host, port, ds._root_token)
|
||||
url = "http://{}:{}{}?token={}".format(
|
||||
host, port, ds.urls.path("-/auth-token"), ds._root_token
|
||||
)
|
||||
print(url)
|
||||
else:
|
||||
url = "http://{}:{}/".format(host, port)
|
||||
url = "http://{}:{}{}".format(host, port, ds.urls.instance())
|
||||
if open_browser:
|
||||
webbrowser.open(url)
|
||||
uvicorn.run(
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
<p>You are logged in as <strong>{{ display_actor(actor) }}</strong></p>
|
||||
|
||||
<form action="/-/logout" method="post">
|
||||
<form action="{{ urls.logout() }}" method="post">
|
||||
<div>
|
||||
<input type="hidden" name="csrftoken" value="{{ csrftoken() }}">
|
||||
<input type="submit" value="Log out">
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<p>Set a message:</p>
|
||||
|
||||
<form action="/-/messages" method="post">
|
||||
<form action="{{ urls.path('-/messages') }}" method="post">
|
||||
<div>
|
||||
<input type="text" name="message" style="width: 40%">
|
||||
<div class="select-wrapper">
|
||||
|
|
|
@ -218,7 +218,7 @@ class DataView(BaseView):
|
|||
elif kwargs.get("table"):
|
||||
kwargs["table"] = urllib.parse.unquote_plus(kwargs["table"])
|
||||
|
||||
should_redirect = "/{}-{}".format(name, expected)
|
||||
should_redirect = self.ds.urls.path("{}-{}".format(name, expected))
|
||||
if kwargs.get("table"):
|
||||
should_redirect += "/" + urllib.parse.quote_plus(kwargs["table"])
|
||||
if kwargs.get("pk_path"):
|
||||
|
|
|
@ -64,7 +64,7 @@ class AuthTokenView(BaseView):
|
|||
raise Forbidden("Root token has already been used")
|
||||
if secrets.compare_digest(token, self.ds._root_token):
|
||||
self.ds._root_token = None
|
||||
response = Response.redirect("/")
|
||||
response = Response.redirect(self.ds.urls.instance())
|
||||
response.set_cookie(
|
||||
"ds_actor", self.ds.sign({"a": {"id": "root"}}, "actor")
|
||||
)
|
||||
|
@ -81,7 +81,7 @@ class LogoutView(BaseView):
|
|||
|
||||
async def get(self, request):
|
||||
if not request.actor:
|
||||
return Response.redirect("/")
|
||||
return Response.redirect(self.ds.urls.instance())
|
||||
return await self.render(
|
||||
["logout.html"],
|
||||
request,
|
||||
|
@ -89,7 +89,7 @@ class LogoutView(BaseView):
|
|||
)
|
||||
|
||||
async def post(self, request):
|
||||
response = Response.redirect("/")
|
||||
response = Response.redirect(self.ds.urls.instance())
|
||||
response.set_cookie("ds_actor", "", expires=0, max_age=0)
|
||||
self.ds.add_message(request, "You are now logged out", self.ds.WARNING)
|
||||
return response
|
||||
|
@ -172,4 +172,4 @@ class MessagesDebugView(BaseView):
|
|||
datasette.add_message(request, message, datasette.ERROR)
|
||||
else:
|
||||
datasette.add_message(request, message, getattr(datasette, message_type))
|
||||
return Response.redirect("/")
|
||||
return Response.redirect(self.ds.urls.instance())
|
||||
|
|
|
@ -272,7 +272,7 @@ Some examples:
|
|||
base_url
|
||||
~~~~~~~~
|
||||
|
||||
If you are running Datasette behind a proxy, it may be useful to change the root URL used for the Datasette instance.
|
||||
If you are running Datasette behind a proxy, it may be useful to change the root path used for the Datasette instance.
|
||||
|
||||
For example, if you are sending traffic from ``https://www.example.com/tools/datasette/`` through to a proxied Datasette instance you may wish Datasette to use ``/tools/datasette/`` as its root URL.
|
||||
|
||||
|
|
|
@ -1360,8 +1360,6 @@ def test_metadata_sort_desc(app_client):
|
|||
assert list(reversed(expected)) == rows
|
||||
|
||||
|
||||
@pytest.mark.xfail
|
||||
@pytest.mark.parametrize("base_url", ["/prefix/", "https://example.com/"])
|
||||
@pytest.mark.parametrize(
|
||||
"path",
|
||||
[
|
||||
|
@ -1373,7 +1371,8 @@ def test_metadata_sort_desc(app_client):
|
|||
"/fixtures/facetable",
|
||||
],
|
||||
)
|
||||
def test_base_url_config(base_url, path):
|
||||
def test_base_url_config(path):
|
||||
base_url = "/prefix/"
|
||||
with make_app_client(config={"base_url": base_url}) as client:
|
||||
response = client.get(base_url + path.lstrip("/"))
|
||||
soup = Soup(response.body, "html.parser")
|
||||
|
|
Ładowanie…
Reference in New Issue