Skip to content

Commit

Permalink
removed namespace for standalone apps
Browse files Browse the repository at this point in the history
updated get_active_app to just grab the standalone app if MULTIPLE_APP_MODE is turned off
  • Loading branch information
ckrew committed Mar 14, 2024
1 parent ea2c917 commit 19feefa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
8 changes: 4 additions & 4 deletions tests/unit_tests/test_tethys_apps/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ def test_urls(self):
url = reverse("home")
resolver = resolve(url)
self.assertEqual("/", url)
self.assertEqual("RedirectView", resolver.func.__name__)
self.assertEqual("/test-app/", resolver.func.view_initkwargs["url"])
self.assertEqual("home", resolver.func.__name__)
self.assertEqual("tethysapp.test_app.controllers", resolver.func.__module__)

url = reverse("app_library")
resolver = resolve(url)
self.assertEqual("/apps/", url)
self.assertEqual("RedirectView", resolver.func.__name__)
self.assertEqual("/test-app/", resolver.func.view_initkwargs["url"])
self.assertEqual("", resolver.func.view_initkwargs["url"])

url = reverse("send_beta_feedback")
resolver = resolve(url)
Expand All @@ -161,7 +161,7 @@ def test_urls(self):

url = reverse("test_app:home")
resolver = resolve(url)
self.assertEqual("/test-app/", url)
self.assertEqual("/", url)
self.assertEqual("home", resolver.func.__name__)
self.assertEqual("tethysapp.test_app.controllers", resolver.func.__module__)

Expand Down
25 changes: 17 additions & 8 deletions tethys_apps/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@
[
re_path(
r"^apps/",
RedirectView.as_view(url=f"/{standalone_app.root_url}/"),
RedirectView.as_view(url=f""),
name="app_library",
),
re_path(
r"^$",
RedirectView.as_view(url=f"/{standalone_app.root_url}/"),
name="home",
),
)
]
)
url_namespaces = [standalone_app.url_namespace]
Expand All @@ -52,6 +47,7 @@
handler_url_patterns = harvester.get_handler_patterns(url_namespaces=url_namespaces)

# configure handler HTTP routes
## Nathan, what would be an example of these?
http_handler_patterns = []
for namespace, urls in handler_url_patterns["http_handler_patterns"].items():
root_pattern = r"^apps/{0}/".format(namespace.replace("_", "-"))
Expand All @@ -61,7 +57,20 @@

# Add app url patterns to urlpatterns, namespaced per app appropriately
for namespace, urls in normal_url_patterns["app_url_patterns"].items():
root_pattern = r"^{0}/".format(namespace.replace("_", "-"))
if settings.MULTIPLE_APP_MODE:
root_pattern = r"^{0}/".format(namespace.replace("_", "-"))
else:
root_pattern = ""
home_urls = [url for url in urls if url.name == "home"]
urlpatterns.append(
re_path(
r"",
include(home_urls[:1]),
name="home",
),
)


urlpatterns.append(
re_path(root_pattern, include((urls, namespace), namespace=namespace))
)
Expand Down
32 changes: 13 additions & 19 deletions tethys_apps/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,19 @@ def get_active_app(request=None, url=None, get_class=False):
"""
from tethys_apps.models import TethysApp

if request is not None:
the_url = request.path
elif url is not None:
the_url = url
else:
return None

url_parts = the_url.split("/")
app = None

# Find the app key
if settings.MULTIPLE_APP_MODE:
apps_root = "apps"
else:
configured_single_app = get_configured_standalone_app()
apps_root = configured_single_app.root_url
if request is not None:
the_url = request.path
elif url is not None:
the_url = url
else:
return None

# Find the app key
if apps_root in url_parts:
if settings.MULTIPLE_APP_MODE:
url_parts = the_url.split("/")
app = None
apps_root = "apps"
if apps_root in url_parts:
# The app root_url is the path item following (+1) the apps_root item
app_root_url_index = url_parts.index(apps_root) + 1
app_root_url = url_parts[app_root_url_index]
Expand All @@ -166,8 +160,8 @@ def get_active_app(request=None, url=None, get_class=False):
tethys_log.warning(
'Multiple apps found with root url "{0}".'.format(app_root_url)
)
else:
app = configured_single_app
else:
app = get_configured_standalone_app()

if get_class:
app = get_app_class(app)
Expand Down

0 comments on commit 19feefa

Please sign in to comment.