Skip to content

Commit 99a4cac

Browse files
JulianFeinauerNiklasMerz
authored andcommitted
refactor: remove launcher pseudo-app
Removes launcher pseudo app and solely relies on omap.py to start the platform
1 parent 0f5a774 commit 99a4cac

File tree

7 files changed

+50
-62
lines changed

7 files changed

+50
-62
lines changed

manage.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

omap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def main():
1010
"""Run administrative tasks."""
11-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "omap.launcher.settings")
11+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "omap.modules.base_settings")
1212
# Here we set the OMAP_MODULES env varible, if not set
1313
os.environ.setdefault("OMAP_MODULES", "")
1414

omap/launcher/__init__.py

Whitespace-only changes.

omap/launcher/urls.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

omap/launcher/settings.py renamed to omap/modules/base_settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,3 @@
111111
INTERNAL_IPS = [
112112
"127.0.0.1",
113113
]
114-
115-
ROOT_URLCONF = "omap.launcher.urls"

omap/modules/module_urls.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import importlib
2+
import logging
3+
4+
from django.apps import apps
5+
from django.conf import settings
6+
from django.conf.urls import url, include
7+
from django.conf.urls.static import static
8+
from django.contrib import admin
9+
from django.urls import path
10+
11+
12+
def dynamic_url():
13+
_urlpatterns = [url(r"admin/", admin.site.urls)] + (
14+
static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
15+
if settings.MEDIA_ROOT
16+
else []
17+
)
18+
19+
"""
20+
Here, apps are registered automatically with their urls if they have a property "url_prefix" set in their AppConfig
21+
AND if they have a valid urls.py file which sets a variable urlpatterns
22+
"""
23+
for config in apps.get_app_configs():
24+
if hasattr(config, "url_prefix"):
25+
logging.debug(
26+
f"Found url_prefix in {config.name}, checking for .urls module"
27+
)
28+
urls_path = config.module.__name__ + ".urls"
29+
try:
30+
importlib.import_module(urls_path)
31+
except ModuleNotFoundError:
32+
logging.debug(f"No url module found under {urls_path}", exc_info=True)
33+
continue
34+
35+
logging.debug(
36+
f"urls.py present under {urls_path}, setting for prefix {config.url_prefix}"
37+
)
38+
# Do the include
39+
_urlpatterns.append(path(config.url_prefix + "/", include(urls_path)))
40+
41+
logging.debug(f"Patterns: {_urlpatterns}")
42+
43+
return _urlpatterns
44+
45+
46+
urlpatterns = dynamic_url()

omap/modules/modules.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ def configure_modules():
253253
merged.update({"INSTALLED_APPS": merged_apps})
254254
merged.update({"CONSTANCE_CONFIG": merged_constance})
255255

256+
# TEST for dynamic urls
257+
merged.update({"ROOT_URLCONF": "omap.modules.module_urls"})
258+
256259
settings.configure(**merged)
257260

258261
# Now modify the INSTALLED_APPS for all apps that contain a urls.py file

0 commit comments

Comments
 (0)