mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-21 23:33:54 +02:00
Added base-path support in URL generating features (#288)
Add the basepath dash url to the path generation for dynamicly generated links.
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
"""Main Dash app."""
|
"""Main Dash app."""
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import dash
|
import dash
|
||||||
@ -56,6 +57,8 @@ def go_to_home(click: int) -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
Returns the href of the home page.
|
Returns the href of the home page.
|
||||||
"""
|
"""
|
||||||
|
if home_path := os.getenv("DASH_URL_BASE_PATHNAME"):
|
||||||
|
return f"{home_path}"
|
||||||
return "/"
|
return "/"
|
||||||
|
|
||||||
|
|
||||||
@ -74,11 +77,14 @@ def go_to_detail_page(id: str) -> str:
|
|||||||
Returns the href of the company page.
|
Returns the href of the company page.
|
||||||
"""
|
"""
|
||||||
if id.startswith("p_"):
|
if id.startswith("p_"):
|
||||||
page = "/Personendetails/"
|
page = "personendetails"
|
||||||
if id.startswith("c_"):
|
if id.startswith("c_"):
|
||||||
page = "/Unternehmensdetails/"
|
page = "unternehmensdetails"
|
||||||
chosen_id = id.split("_", 1)[1]
|
chosen_id = id.split("_", 1)[1]
|
||||||
return f"{page}{chosen_id}"
|
url = f"/{page}/{chosen_id}"
|
||||||
|
if prefix := os.getenv("DASH_URL_BASE_PATHNAME"):
|
||||||
|
return f"{prefix}{url}".replace("//", "/").replace("//", "/")
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
@app.callback(
|
@app.callback(
|
||||||
|
@ -10,7 +10,7 @@ from aki_prj23_transparenzregister.ui import (
|
|||||||
from aki_prj23_transparenzregister.ui.session_handler import SessionHandler
|
from aki_prj23_transparenzregister.ui.session_handler import SessionHandler
|
||||||
|
|
||||||
dash.register_page(
|
dash.register_page(
|
||||||
__name__, path_template="/Unternehmensdetails/<value>", title="Unternehmensdetails"
|
__name__, path_template="/unternehmensdetails/<value>", title="Unternehmensdetails"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ from aki_prj23_transparenzregister.ui import data_elements, header_elements
|
|||||||
from aki_prj23_transparenzregister.ui.session_handler import SessionHandler
|
from aki_prj23_transparenzregister.ui.session_handler import SessionHandler
|
||||||
|
|
||||||
dash.register_page(
|
dash.register_page(
|
||||||
__name__, path_template="/Personendetails/<value>", title="Personendetails"
|
__name__, path_template="/personendetails/<value>", title="Personendetails"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,10 +31,17 @@ def test_go_to_home() -> None:
|
|||||||
assert output == "/"
|
assert output == "/"
|
||||||
|
|
||||||
|
|
||||||
def test_go_to_detail_page() -> None:
|
def test_go_to_detail_page1(monkeypatch: MonkeyPatch) -> None:
|
||||||
|
"""Checks if the go_to_detail_page callback yields a result."""
|
||||||
|
monkeypatch.setenv("DASH_URL_BASE_PATHNAME", "/monkey_path/")
|
||||||
|
output = app.go_to_detail_page("c_1")
|
||||||
|
assert output == "/monkey_path/unternehmensdetails/1"
|
||||||
|
|
||||||
|
|
||||||
|
def test_go_to_detail_page2() -> None:
|
||||||
"""Checks if the go_to_detail_page callback yields a result."""
|
"""Checks if the go_to_detail_page callback yields a result."""
|
||||||
output = app.go_to_detail_page("c_1")
|
output = app.go_to_detail_page("c_1")
|
||||||
assert output == "/Unternehmensdetails/1"
|
assert output == "/unternehmensdetails/1"
|
||||||
|
|
||||||
|
|
||||||
def test_main_of_app(monkeypatch: MonkeyPatch) -> None:
|
def test_main_of_app(monkeypatch: MonkeyPatch) -> None:
|
||||||
|
Reference in New Issue
Block a user