aboutsummaryrefslogtreecommitdiffstats
path: root/lib/srtmain/urls.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/srtmain/urls.py')
-rw-r--r--lib/srtmain/urls.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/srtmain/urls.py b/lib/srtmain/urls.py
index 2f330154..6bdc1581 100644
--- a/lib/srtmain/urls.py
+++ b/lib/srtmain/urls.py
@@ -22,7 +22,7 @@
import os
from django import VERSION as DJANGO_VERSION
-from django.conf.urls import url
+from django.urls import re_path as url
from django.views.generic import RedirectView, TemplateView
from django.views.decorators.cache import never_cache
@@ -39,6 +39,9 @@ logger = logging.getLogger("srt")
from django.contrib import admin
admin.autodiscover()
+# Fetch the main app URL
+SRT_MAIN_APP = os.environ.get('SRT_MAIN_APP', 'srtgui')
+
urlpatterns = [
# Examples:
@@ -50,7 +53,7 @@ urlpatterns = [
url(r'^health$', TemplateView.as_view(template_name="health.html"), name='Toaster Health'),
# if no application is selected, we have the magic srtgui app here
- url(r'^$', never_cache(RedirectView.as_view(url='/srtgui/', permanent=True))),
+ url(r'^$', never_cache(RedirectView.as_view(url='/'+SRT_MAIN_APP+'/', permanent=True)), name='Default URL=/'+SRT_MAIN_APP+'/'),
]
import srtmain.settings
@@ -76,12 +79,12 @@ if DJANGO_VERSION >= (2,0):
# Uncomment the next lines to enable the admin:
path('admin/', admin.site.urls),
- # Main application
- path(SRT_MAIN_APP + '/', include(SRT_MAIN_APP + '.urls')),
# Default applications
path('srtgui/', include('srtgui.urls')),
path('users/', include('users.urls')),
path('users/', include('django.contrib.auth.urls')),
+ # Main application
+ path(SRT_MAIN_APP + '/', include(SRT_MAIN_APP + '.urls')),
] + urlpatterns
else:
urlpatterns = [
@@ -96,7 +99,26 @@ else:
url('^' + SRT_MAIN_APP + '/', include(SRT_MAIN_APP + '.urls')),
] + urlpatterns
-#print("DEBUG:INSTALLED_URL_PATTERNS:%s,%s" % (SRT_MAIN_APP,urlpatterns))
+
+# We automatically detect and install other applications here
+# (at a lower precedence) if they have a 'urls.py'
+currentdir = os.path.dirname(__file__)
+urlpatterns_str = str(urlpatterns)
+for t in os.walk(os.path.dirname(currentdir)):
+ modulename = os.path.basename(t[0])
+ if 'srtmain' == modulename:
+ # Avoid infinite recursion
+ continue
+ if "urls.py" in t[2]:
+ found = False
+ for url in urlpatterns:
+ if modulename+"/urls.py" in str(url):
+ found = True
+ if not found:
+# urlpatterns.append(path(modulename + '/', include(modulename + '.urls')))
+ urlpatterns.insert(0,path(modulename + '/', include(modulename + '.urls')))
+
+##print("DEBUG:INSTALLED_URL_PATTERNS:%s,%s" % (SRT_MAIN_APP,urlpatterns))
currentdir = os.path.dirname(__file__)