_original_make_action_button = Grid._make_action_button
def patched_make_action_button(self, text, url, *args, **kwargs):
base = request.environ.get("SCRIPT_NAME", "")
if base and url.startswith("/") and not url.startswith(base + "/"):
url = base + url
return _original_make_action_button(self, text, url, *args, **kwargs)
Grid._make_action_button = patched_make_action_button
app = wsgi(
apps_folder=APPS_FOLDER,
password_file="./password.txt",
dashboard_mode="full"
)
Ideally, we would like to see the SCRIPT_NAME taken into account in the function itself. I just wanted to check if there isn't some other way of achieving the same result in py4web before entering a PR for the change below.
def _make_action_button(
self,
text,
url,
icon=None,
classes=None,
kind="grid-button",
**attrs,
):
if kind:
classes = join_classes(classes, self.get_style(kind))
if not "_role" in attrs:
attrs["_role"] = "button"
# FIX FOR GRID AND DBADMIN IN DASHBOARD
# ✅ ADD THIS BLOCK
base = request.environ.get("SCRIPT_NAME", "")
if base and url.startswith("/") and not url.startswith(base + "/"):
url = base + url
# ✅ END FIX
link = A(
I(_class=self.param.icon_style.complete(icon)) if icon else "",
_class=classes,
_href=url,
**attrs,
)
if self.param.include_action_button_text:
link.append(
SPAN(
XML(" "),
text,
_class=self.get_style(kind + "-text") if kind else None,
)
)
return link