From cd8cd40626a51db0bdbb3daacbeccf95bf1d0717 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 1 Aug 2021 18:39:01 +0200 Subject: [PATCH] hook to add local urls --- pandora/settings.py | 2 +- pandora/urls.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pandora/settings.py b/pandora/settings.py index 69a76e0b9..af0283315 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -278,6 +278,7 @@ DATA_UPLOAD_MAX_MEMORY_SIZE = 32 * 1024 * 1024 #you can ignore things below this line #========================================================================= LOCAL_APPS = [] +LOCAL_URLPATTERNS = [] #load installation specific settings from local_settings.py try: from local_settings import * @@ -304,4 +305,3 @@ except NameError: INSTALLED_APPS = tuple(list(INSTALLED_APPS) + LOCAL_APPS) - diff --git a/pandora/urls.py b/pandora/urls.py index cd241d664..5c7aad4df 100644 --- a/pandora/urls.py +++ b/pandora/urls.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import os +import importlib from django.urls import path, re_path from oxdjango.http import HttpFileResponse @@ -88,3 +89,17 @@ urlpatterns += [ path(r'', app.views.index), ] +if settings.LOCAL_URLPATTERNS: + patterns = [] + for pattern, fn in settings.LOCAL_URLPATTERNS: + if isinstnace(fn, 'str'): + m, f = fn.rsplit('.', 1) + try: + m = importlib.import_module(m) + except ImportError: + logger.error('failed to import urllib module: %s', fn, exc_info=True) + continue + fn = getattr(m, f) + patterns.append(re_path(pattern, fn)) + urlpatterns = patterns + urlpatterns +